summaryrefslogtreecommitdiff
path: root/bundle.c
diff options
context:
space:
mode:
authorThomas Rast <trast@student.ethz.ch>2011-08-29 21:16:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-08-29 22:54:54 (GMT)
commit8c74ef1e972df2aebc403ee807992017e9cc6838 (patch)
tree0c6f6bc2a452bf2e89c2db1430e4dc79eb16f67e /bundle.c
parentf696543dad6c7ba27b0c4fab167a5687263a9ba0 (diff)
downloadgit-8c74ef1e972df2aebc403ee807992017e9cc6838.zip
git-8c74ef1e972df2aebc403ee807992017e9cc6838.tar.gz
git-8c74ef1e972df2aebc403ee807992017e9cc6838.tar.bz2
strbuf_grow(): maintain nul-termination even for new buffer
In the case where sb is initialized to the slopbuf (through strbuf_init(sb,0) or STRBUF_INIT), strbuf_grow() loses the terminating nul: it grows the buffer, but gives ALLOC_GROW a NULL source to avoid it being freed. So ALLOC_GROW does not copy anything to the new memory area. This subtly broke the call to strbuf_getline in read_next_command() [fast-import.c:1855], which goes strbuf_detach(&command_buf, NULL); # command_buf is now = STRBUF_INIT stdin_eof = strbuf_getline(&command_buf, stdin, '\n'); if (stdin_eof) return EOF; In strbuf_getwholeline, this did strbuf_grow(sb, 0); # loses nul-termination if (feof(fp)) return EOF; strbuf_reset(sb); # this would have nul-terminated! Valgrind found this because fast-import subsequently uses prefixcmp() on command_buf.buf, which after the EOF exit contains only uninitialized memory. Arguably strbuf_getwholeline is also broken, in that it touches the buffer before deciding whether to do any work. However, it seems more futureproof to not let the strbuf API lose the nul-termination by its own fault. So make sure that strbuf_grow() puts in a nul even if it has nowhere to copy it from. This makes strbuf_grow(sb, 0) a semantic no-op as far as readers of the buffer are concerned. Also remove the nul-termination added by strbuf_init, which is made redudant. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'bundle.c')
0 files changed, 0 insertions, 0 deletions