From: Junio C Hamano Date: Fri, 15 Apr 2016 01:57:46 +0000 (-0700) Subject: Merge branch 'jk/getwholeline-getdelim-empty' into maint X-Git-Tag: v2.8.2~16 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f55f97cb3307f49e6b15d9f0145b6d3f00b22ff7?hp=183ecc3e49dee55de349e2f0759aa4894b3623c7 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 --- diff --git a/strbuf.c b/strbuf.c index f60e2ee72b..2c08dbb153 100644 --- a/strbuf.c +++ b/strbuf.c @@ -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 input <<-INPUT_END &&