read_and_strip_branch: fix typo'd address-of operator
authorJeff King <peff@peff.net>
Wed, 28 Jan 2015 17:57:35 +0000 (12:57 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 28 Jan 2015 20:42:44 +0000 (12:42 -0800)
When we are chomping newlines from the end of a strbuf, we
must check "sb.len != 0" before accessing "sb.buf[sb.len - 1]".
However, this code mistakenly checks "&sb.len", which is
always true (it is a part of an auto struct, so the address
is always non-zero). This could lead to us accessing memory
outside the strbuf when we read an empty file.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
wt-status.c
index aa53436118b6232c56af29c95bcfbfa9427efb54..a30ca97fc832d0ebcbdfafdb960ad6c440d340b2 100644 (file)
@@ -975,7 +975,7 @@ static char *read_and_strip_branch(const char *path)
        if (strbuf_read_file(&sb, git_path("%s", path), 0) <= 0)
                goto got_nothing;
 
-       while (&sb.len && sb.buf[sb.len - 1] == '\n')
+       while (sb.len && sb.buf[sb.len - 1] == '\n')
                strbuf_setlen(&sb, sb.len - 1);
        if (!sb.len)
                goto got_nothing;