rerere forget: grok files containing NUL
authorJohannes Sixt <j6t@kdbg.org>
Mon, 1 Apr 2013 21:36:36 +0000 (23:36 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Apr 2013 20:00:41 +0000 (13:00 -0700)
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>
rerere.c
t/t2030-unresolve-info.sh
index a6a5cd57bef4aaf204f1bad293c18b5af6f57f53..4d940cd37594e8483356ec6c52637c778d8c9895 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -284,8 +284,10 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)
        strbuf_release(sb);
        if (!io->input.len)
                return -1;
        strbuf_release(sb);
        if (!io->input.len)
                return -1;
-       ep = strchrnul(io->input.buf, '\n');
-       if (*ep == '\n')
+       ep = memchr(io->input.buf, '\n', io->input.len);
+       if (!ep)
+               ep = io->input.buf + io->input.len;
+       else if (*ep == '\n')
                ep++;
        len = ep - io->input.buf;
        strbuf_add(sb, io->input.buf, len);
                ep++;
        len = ep - io->input.buf;
        strbuf_add(sb, io->input.buf, len);
index f2620650ce1d25252210c07db20e54f99bd515c6..0b699f50dd17b884c391135c2e18ca6b6df0b51a 100755 (executable)
@@ -44,9 +44,13 @@ prime_resolve_undo () {
 
 test_expect_success setup '
        mkdir fi &&
 
 test_expect_success setup '
        mkdir fi &&
+       printf "a\0a" >binary &&
+       git add binary &&
        test_commit initial fi/le first &&
        git branch side &&
        git branch another &&
        test_commit initial fi/le first &&
        git branch side &&
        git branch another &&
+       printf "a\0b" >binary &&
+       git add binary &&
        test_commit second fi/le second &&
        git checkout side &&
        test_commit third fi/le third &&
        test_commit second fi/le second &&
        git checkout side &&
        test_commit third fi/le third &&
@@ -167,4 +171,12 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
        test_cmp expect actual
 '
 
        test_cmp expect actual
 '
 
+test_expect_success 'rerere forget (binary)' '
+       git checkout -f side &&
+       printf "a\0c" >binary &&
+       git commit -a -m binary &&
+       test_must_fail git merge second &&
+       git rerere forget binary
+'
+
 test_done
 test_done