From 4bdb664c330d6f5ffb9613ee78c8f7866a6eea05 Mon Sep 17 00:00:00 2001 From: Olaf Flebbe Date: Tue, 27 Mar 2012 09:32:19 +0200 Subject: 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 --- src/tool_cb_dbg.c | 22 ++++++++++++---------- 1 file 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; -- cgit v1.2.3