show-branch: use a strbuf for reflog descriptions
When we show "branch@{0}", we format into a fixed-size buffer using sprintf. This can overflow if you have long branch names. We can fix it by using a temporary strbuf. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Aug 19, 2015 at 14:12 UTC
78f23bdf68dae56d644892990484951583a64014
1 file changed
+4
-2
builtin/show-branch.c
+4
-2
@@ -720,7 +720,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
720
721
if (reflog) {
722
unsigned char sha1[20];
723
- char nth_desc[256];
723
char *ref;
724
int base = 0;
725
unsigned int flags = 0;
@@ -759,6 +758,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
758
759
for (i = 0; i < reflog; i++) {
760
char *logmsg;
761
+ char *nth_desc;
762
const char *msg;
763
unsigned long timestamp;
764
int tz;
@@ -777,8 +777,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
777
show_date(timestamp, tz, 1),
778
msg);
779
free(logmsg);
780
- sprintf(nth_desc, "%s@{%d}", *av, base+i);
780
+
781
+ nth_desc = xstrfmt("%s@{%d}", *av, base+i);
782
append_ref(nth_desc, sha1, 1);
783
+ free(nth_desc);
784
}
785
free(ref);
786
}