diff options
author | Olaf Flebbe <o.flebbe@science-computing.de> | 2012-03-27 09:32:19 +0200 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2012-03-27 22:16:25 +0200 |
commit | 4bdb664c330d6f5ffb9613ee78c8f7866a6eea05 (patch) | |
tree | a28669d5df1fa25498e814df199d246ba50462a9 /src/tool_cb_dbg.c | |
parent | 459435dca17f65955d9d98885f604b1fe495289a (diff) | |
download | curl-4bdb664c330d6f5ffb9613ee78c8f7866a6eea05.tar.gz |
tool_cb_dbg.c: fix tool_cb_dbg() to behave properly even for size 0
curl segfault in debug callback triggered with CURLINFO_HEADER_OUT and size 0
bug: http://curl.haxx.se/bug/view.cgi?id=3511794
Diffstat (limited to 'src/tool_cb_dbg.c')
-rw-r--r-- | src/tool_cb_dbg.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/tool_cb_dbg.c b/src/tool_cb_dbg.c index 7ac9a7339..e92ad1ade 100644 --- a/src/tool_cb_dbg.c +++ b/src/tool_cb_dbg.c @@ -108,19 +108,21 @@ int tool_debug_cb(CURL *handle, curl_infotype type, switch(type) { case CURLINFO_HEADER_OUT: - for(i = 0; i < size - 1; i++) { - if(data[i] == '\n') { /* LF */ - if(!newl) { - fprintf(output, "%s%s ", timebuf, s_infotype[type]); + if(size > 0) { + for(i = 0; i < size - 1; i++) { + if(data[i] == '\n') { /* LF */ + if(!newl) { + fprintf(output, "%s%s ", timebuf, s_infotype[type]); + } + (void)fwrite(data + st, i - st + 1, 1, output); + st = i + 1; + newl = FALSE; } - (void)fwrite(data + st, i - st + 1, 1, output); - st = i + 1; - newl = FALSE; } + if(!newl) + fprintf(output, "%s%s ", timebuf, s_infotype[type]); + (void)fwrite(data + st, i - st + 1, 1, output); } - if(!newl) - fprintf(output, "%s%s ", timebuf, s_infotype[type]); - (void)fwrite(data + st, i - st + 1, 1, output); newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE; traced_data = FALSE; break; |