Skip to content

Commit 66ec904

Browse files
peffgitster
authored andcommitted
read_and_strip_branch: fix typo'd address-of operator
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8b87cfd commit 66ec904

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ static char *read_and_strip_branch(const char *path)
975975
if (strbuf_read_file(&sb, git_path("%s", path), 0) <= 0)
976976
goto got_nothing;
977977

978-
while (&sb.len && sb.buf[sb.len - 1] == '\n')
978+
while (sb.len && sb.buf[sb.len - 1] == '\n')
979979
strbuf_setlen(&sb, sb.len - 1);
980980
if (!sb.len)
981981
goto got_nothing;

0 commit comments

Comments
 (0)