Skip to content

Commit

Permalink
Merge branch 'jk/getwholeline-getdelim-empty'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed Apr 3, 2016
2 parents aa3a2c2 + b709043 commit 087f171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,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
Expand Down
4 changes: 4 additions & 0 deletions t/t9300-fast-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 087f171

Please sign in to comment.