rerere forget: grok files containing NUL
Using 'git rerere forget .' after a merge that involved binary files runs into an infinite loop if the binary file contains a zero byte. Replace a strchrnul by memchr because the former does not make progress as soon as the NUL is encountered. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Apr 1, 2013 at 23:36 UTC
53d8afafbbf455d24b0a94e4114709a4d495d460
2 files changed
+16
-2
rerere.c
+4
-2
@@ -284,8 +284,10 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
284
strbuf_release(sb);
285
if (!io->input.len)
286
return -1;
287
- ep = strchrnul(io->input.buf, '\n');
288
- if (*ep == '\n')
287
+ ep = memchr(io->input.buf, '\n', io->input.len);
288
+ if (!ep)
289
+ ep = io->input.buf + io->input.len;
290
+ else if (*ep == '\n')
291
ep++;
292
len = ep - io->input.buf;
293
strbuf_add(sb, io->input.buf, len);
t/t2030-unresolve-info.sh
+12
@@ -44,9 +44,13 @@ prime_resolve_undo () {
44
45
test_expect_success setup '
46
mkdir fi &&
47
+ printf "a\0a" >binary &&
48
+ git add binary &&
49
test_commit initial fi/le first &&
50
git branch side &&
51
git branch another &&
52
+ printf "a\0b" >binary &&
53
+ git add binary &&
54
test_commit second fi/le second &&
55
git checkout side &&
56
test_commit third fi/le third &&
@@ -167,4 +171,12 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
171
test_cmp expect actual
172
'
173
174
+test_expect_success 'rerere forget (binary)' '
175
+ git checkout -f side &&
176
+ printf "a\0c" >binary &&
177
+ git commit -a -m binary &&
178
+ test_must_fail git merge second &&
179
+ git rerere forget binary
180
+'
181
+
182
test_done