diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-04-14 18:57:46 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-04-14 18:57:46 -0700 |
commit | f55f97cb3307f49e6b15d9f0145b6d3f00b22ff7 (patch) | |
tree | 0460b6a32f3f3cf4877f9dd681cd971e644a80a2 | |
parent | Merge branch 'rj/xdiff-prepare-plug-leak-on-error-codepath' into maint (diff) | |
parent | strbuf_getwholeline: NUL-terminate getdelim buffer on error (diff) | |
download | tgif-f55f97cb3307f49e6b15d9f0145b6d3f00b22ff7.tar.xz |
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
-rw-r--r-- | strbuf.c | 8 | ||||
-rwxr-xr-x | t/t9300-fast-import.sh | 4 |
2 files changed, 11 insertions, 1 deletions
@@ -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 diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 4c5f3c9d41..25bb60b281 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 && |