Skip to content

Commit f55f97c

Browse files
committed
Merge branch 'jk/getwholeline-getdelim-empty' into maint
strbuf_getwholeline() did not NUL-terminate the buffer on certain corner cases in its error codepath. * jk/getwholeline-getdelim-empty: strbuf_getwholeline: NUL-terminate getdelim buffer on error
2 parents 183ecc3 + b709043 commit f55f97c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

strbuf.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,15 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
481481
if (errno == ENOMEM)
482482
die("Out of memory, getdelim failed");
483483

484-
/* Restore slopbuf that we moved out of the way before */
484+
/*
485+
* Restore strbuf invariants; if getdelim left us with a NULL pointer,
486+
* we can just re-init, but otherwise we should make sure that our
487+
* length is empty, and that the result is NUL-terminated.
488+
*/
485489
if (!sb->buf)
486490
strbuf_init(sb, 0);
491+
else
492+
strbuf_reset(sb);
487493
return EOF;
488494
}
489495
#else

t/t9300-fast-import.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ test_expect_success 'empty stream succeeds' '
5555
git fast-import </dev/null
5656
'
5757

58+
test_expect_success 'truncated stream complains' '
59+
echo "tag foo" | test_must_fail git fast-import
60+
'
61+
5862
test_expect_success 'A: create pack from stdin' '
5963
test_tick &&
6064
cat >input <<-INPUT_END &&

0 commit comments

Comments
 (0)