diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-04-03 19:29:34 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-04-03 19:29:34 +0200 |
commit | 087f171f1401f15672821d8a661ad736a3b296f3 (patch) | |
tree | 7eae3fbfaabe04edf3bf1065ea6e649f59f14eea /strbuf.c | |
parent | Merge branch 'rj/xdiff-prepare-plug-leak-on-error-codepath' (diff) | |
parent | strbuf_getwholeline: NUL-terminate getdelim buffer on error (diff) | |
download | git-087f171f1401f15672821d8a661ad736a3b296f3.tar.xz git-087f171f1401f15672821d8a661ad736a3b296f3.zip |
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 |