summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-10-19 16:31:20 -0400
committerJunio C Hamano <gitster@pobox.com>2017-10-21 21:12:53 +0900
commitb66b5072921fb706f1e9352f471098c988b0ca39 (patch)
treeb9e4c6bfafda6d25496e15e71d08c0128d714744
parentda58318e76b37c345e4d0da4c42987ad45b4f155 (diff)
downloadgit-jk/diff-color-moved-fix.tar.gz
diff: handle NULs in get_string_hash()jk/diff-color-moved-fix
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--diff.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index 09081a207c..c4a669ffa8 100644
--- a/diff.c
+++ b/diff.c
@@ -782,7 +782,7 @@ static unsigned get_string_hash(struct emitted_diff_symbol *es, struct diff_opti
strbuf_reset(&sb);
while (ae > ap && isspace(ae[-1]))
ae--;
- while ((c = next_byte(&ap, &ae, o)) > 0)
+ while ((c = next_byte(&ap, &ae, o)) >= 0)
strbuf_addch(&sb, c);
return memhash(sb.buf, sb.len);