Skip to content

Commit 78f23bd

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5015f01 commit 78f23bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

builtin/show-branch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
720720

721721
if (reflog) {
722722
unsigned char sha1[20];
723-
char nth_desc[256];
724723
char *ref;
725724
int base = 0;
726725
unsigned int flags = 0;
@@ -759,6 +758,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
759758

760759
for (i = 0; i < reflog; i++) {
761760
char *logmsg;
761+
char *nth_desc;
762762
const char *msg;
763763
unsigned long timestamp;
764764
int tz;
@@ -777,8 +777,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
777777
show_date(timestamp, tz, 1),
778778
msg);
779779
free(logmsg);
780-
sprintf(nth_desc, "%s@{%d}", *av, base+i);
780+
781+
nth_desc = xstrfmt("%s@{%d}", *av, base+i);
781782
append_ref(nth_desc, sha1, 1);
783+
free(nth_desc);
782784
}
783785
free(ref);
784786
}

0 commit comments

Comments
 (0)