Skip to content

Commit

Permalink
show-branch: use a strbuf for reflog descriptions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 4, 2015
1 parent 5015f01 commit 78f23bd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,6 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)

if (reflog) {
unsigned char sha1[20];
char nth_desc[256];
char *ref;
int base = 0;
unsigned int flags = 0;
Expand Down Expand Up @@ -759,6 +758,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)

for (i = 0; i < reflog; i++) {
char *logmsg;
char *nth_desc;
const char *msg;
unsigned long timestamp;
int tz;
Expand All @@ -777,8 +777,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
show_date(timestamp, tz, 1),
msg);
free(logmsg);
sprintf(nth_desc, "%s@{%d}", *av, base+i);

nth_desc = xstrfmt("%s@{%d}", *av, base+i);
append_ref(nth_desc, sha1, 1);
free(nth_desc);
}
free(ref);
}
Expand Down

0 comments on commit 78f23bd

Please sign in to comment.