aboutsummaryrefslogtreecommitdiff
path: root/src/tool_cb_dbg.c
diff options
context:
space:
mode:
authorOlaf Flebbe <o.flebbe@science-computing.de>2012-03-27 09:32:19 +0200
committerYang Tse <yangsita@gmail.com>2012-03-27 22:16:25 +0200
commit4bdb664c330d6f5ffb9613ee78c8f7866a6eea05 (patch)
treea28669d5df1fa25498e814df199d246ba50462a9 /src/tool_cb_dbg.c
parent459435dca17f65955d9d98885f604b1fe495289a (diff)
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.c22
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;