Skip to content

Commit b66b507

Browse files
peffgitster
authored andcommitted
diff: handle NULs in get_string_hash()
For computing moved lines, we feed the characters of each line into a hash. When we've been asked to ignore whitespace, then we pick each character using next_byte(), which returns -1 on end-of-string, which it determines using the start/end pointers we feed it. However our check of its return value treats "0" the same as "-1", meaning we'd quit if the string has an embedded NUL. This is unlikely to ever come up in practice since our line boundaries generally come from calling strlen() in the first place. But it was a bit surprising to me as a reader of the next_byte() code. And it's possible that we may one day feed this function with more exotic input, which otherwise works with arbitrary ptr/len pairs. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da58318 commit b66b507

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ static unsigned get_string_hash(struct emitted_diff_symbol *es, struct diff_opti
782782
strbuf_reset(&sb);
783783
while (ae > ap && isspace(ae[-1]))
784784
ae--;
785-
while ((c = next_byte(&ap, &ae, o)) > 0)
785+
while ((c = next_byte(&ap, &ae, o)) >= 0)
786786
strbuf_addch(&sb, c);
787787

788788
return memhash(sb.buf, sb.len);

0 commit comments

Comments
 (0)