diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-04-03 10:29:34 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-04-03 10:29:34 -0700 |
commit | 087f171f1401f15672821d8a661ad736a3b296f3 (patch) | |
tree | 7eae3fbfaabe04edf3bf1065ea6e649f59f14eea /strbuf.c | |
parent | aa3a2c2af600e6aea73df63c11a0eb88a00b6444 (diff) | |
parent | b70904306fc30857fa3638d2bce7ae0ad1251e23 (diff) | |
download | git-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.c | 8 |
1 files changed, 7 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 |