]> Kevux Git Server - rit/commitdiff
wt-status: avoid building bogus branch name with detached HEAD
authorRené Scharfe <l.s.r@web.de>
Sat, 31 Oct 2015 17:36:35 +0000 (18:36 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 1 Nov 2015 17:58:20 +0000 (09:58 -0800)
If we're on a detached HEAD then wt_shortstatus_print_tracking() takes
the string "HEAD (no branch)", translates it, skips the first eleven
characters and passes the result to branch_get(), which returns a bogus
result and accesses memory out of bounds in order to produce it.
Somehow stat_tracking_info(), which is passed that result, does the
right thing anyway, i.e. it finds that there is no base.

Avoid the bogus results and memory accesses by checking for HEAD first
and exiting early in that case.  This fixes t7060 with --valgrind.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7060-wtstatus.sh
wt-status.c

index 879d0c1..58df3f3 100755 (executable)
@@ -213,7 +213,7 @@ EOF
        git checkout master
 '
 
-test_expect_failure 'status --branch with detached HEAD' '
+test_expect_success 'status --branch with detached HEAD' '
        git reset --hard &&
        git checkout master^0 &&
        git status --branch --porcelain >actual &&
index ac05b9b..0e4a04e 100644 (file)
@@ -1521,16 +1521,19 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
                return;
        branch_name = s->branch;
 
+       if (s->is_initial)
+               color_fprintf(s->fp, header_color, _("Initial commit on "));
+
+       if (!strcmp(s->branch, "HEAD")) {
+               color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s",
+                             _("HEAD (no branch)"));
+               goto conclude;
+       }
+
        if (starts_with(branch_name, "refs/heads/"))
                branch_name += 11;
-       else if (!strcmp(branch_name, "HEAD")) {
-               branch_name = _("HEAD (no branch)");
-               branch_color_local = color(WT_STATUS_NOBRANCH, s);
-       }
 
        branch = branch_get(s->branch + 11);
-       if (s->is_initial)
-               color_fprintf(s->fp, header_color, _("Initial commit on "));
 
        color_fprintf(s->fp, branch_color_local, "%s", branch_name);