summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--strbuf.c8
-rwxr-xr-xt/t9300-fast-import.sh4
2 files changed, 11 insertions, 1 deletions
diff --git a/strbuf.c b/strbuf.c
index d76f0aed85..258650ccb3 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -470,9 +470,15 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
if (errno == ENOMEM)
die("Out of memory, getdelim failed");
- /* Restore slopbuf that we moved out of the way before */
+ /*
+ * Restore strbuf invariants; if getdelim left us with a NULL pointer,
+ * we can just re-init, but otherwise we should make sure that our
+ * length is empty, and that the result is NUL-terminated.
+ */
if (!sb->buf)
strbuf_init(sb, 0);
+ else
+ strbuf_reset(sb);
return EOF;
}
#else
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 14a938402e..95c70ed43e 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -55,6 +55,10 @@ test_expect_success 'empty stream succeeds' '
git fast-import </dev/null
'
+test_expect_success 'truncated stream complains' '
+ echo "tag foo" | test_must_fail git fast-import
+'
+
test_expect_success 'A: create pack from stdin' '
test_tick &&
cat >input <<-INPUT_END &&