summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-04-03 10:29:34 -0700
committerJunio C Hamano <gitster@pobox.com>2016-04-03 10:29:34 -0700
commit087f171f1401f15672821d8a661ad736a3b296f3 (patch)
tree7eae3fbfaabe04edf3bf1065ea6e649f59f14eea /strbuf.c
parentaa3a2c2af600e6aea73df63c11a0eb88a00b6444 (diff)
parentb70904306fc30857fa3638d2bce7ae0ad1251e23 (diff)
downloadgit-087f171f1401f15672821d8a661ad736a3b296f3.tar.gz
Merge branch 'jk/getwholeline-getdelim-empty'
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