Code

fix hang in git fetch if pointed at a 0 length bundle
authorBrian Harring <ferringb@gmail.com>
Tue, 3 Jan 2012 13:46:03 +0000 (05:46 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jan 2012 20:13:28 +0000 (12:13 -0800)
git-repo if interupted at the exact wrong time will generate zero
length bundles- literal empty files.  git-repo is wrong here, but
git fetch shouldn't effectively spin loop if pointed at a zero
length bundle.

Signed-off-by: Brian Harring <ferringb@chromium.org>
Helped-by: Johannes Sixt
Helped-by: Nguyen Thai Ngoc Duy
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bundle.c
t/t5704-bundle.sh

index 08020bc3a258e055a8f5f6974217cf482edc3ee3..8a1d53ba29a434139123bd7d4e37db47ba8728cb 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -31,8 +31,8 @@ static int strbuf_readline_fd(struct strbuf *sb, int fd)
        while (1) {
                char ch;
                ssize_t len = xread(fd, &ch, 1);
-               if (len < 0)
-                       return -1;
+               if (len <= 0)
+                       return len;
                strbuf_addch(sb, ch);
                if (ch == '\n')
                        break;
index 728ccd88c3d69f06bff2c3593ddc325f9186402c..4ae127d106c4a8ada0cea928affeff933bf0dbaa 100755 (executable)
@@ -53,4 +53,10 @@ test_expect_failure 'bundle --stdin <rev-list options>' '
 
 '
 
+test_expect_success 'empty bundle file is rejected' '
+
+    >empty-bundle && test_must_fail git fetch empty-bundle
+
+'
+
 test_done