summaryrefslogtreecommitdiff
path: root/builtin/show-branch.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-08-19 18:12:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-09-04 16:48:26 (GMT)
commit78f23bdf68dae56d644892990484951583a64014 (patch)
tree324187d0682f989593a532d231acf8472d4d2f2b /builtin/show-branch.c
parent5015f01c12a45a1042c1aa6b6f7f6b62bfa00ade (diff)
downloadgit-78f23bdf68dae56d644892990484951583a64014.zip
git-78f23bdf68dae56d644892990484951583a64014.tar.gz
git-78f23bdf68dae56d644892990484951583a64014.tar.bz2
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>
Diffstat (limited to 'builtin/show-branch.c')
-rw-r--r--builtin/show-branch.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 270e39c..9e60b12 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -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;
@@ -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;
@@ -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);
}