show-branch: use a strbuf for reflog descriptions
authorJeff King <peff@peff.net>
Wed, 19 Aug 2015 18:12:48 +0000 (14:12 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 4 Sep 2015 16:48:26 +0000 (09:48 -0700)
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>
builtin/show-branch.c
index 270e39c6c1b0855181a19b12739425035db9ad1d..9e60b12445f9e9a3d203404e0ba5a1cdc39b29ec 100644 (file)
@@ -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);
        }