summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-04-14 18:57:46 -0700
committerJunio C Hamano <gitster@pobox.com>2016-04-14 18:57:46 -0700
commitf55f97cb3307f49e6b15d9f0145b6d3f00b22ff7 (patch)
tree0460b6a32f3f3cf4877f9dd681cd971e644a80a2 /strbuf.c
parent183ecc3e49dee55de349e2f0759aa4894b3623c7 (diff)
parentb70904306fc30857fa3638d2bce7ae0ad1251e23 (diff)
downloadgit-f55f97cb3307f49e6b15d9f0145b6d3f00b22ff7.tar.gz
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
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c8
1 files changed, 7 insertions, 1 deletions
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