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 /strbuf.c | |
parent | 183ecc3e49dee55de349e2f0759aa4894b3623c7 (diff) | |
parent | b70904306fc30857fa3638d2bce7ae0ad1251e23 (diff) | |
download | git-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.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 |