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
This commit is contained in:
Olaf Flebbe 2012-03-27 09:32:19 +02:00 committed by Yang Tse
parent 459435dca1
commit 4bdb664c33
1 changed files with 12 additions and 10 deletions

View File

@ -108,19 +108,21 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
switch(type) { switch(type) {
case CURLINFO_HEADER_OUT: case CURLINFO_HEADER_OUT:
for(i = 0; i < size - 1; i++) { if(size > 0) {
if(data[i] == '\n') { /* LF */ for(i = 0; i < size - 1; i++) {
if(!newl) { if(data[i] == '\n') { /* LF */
fprintf(output, "%s%s ", timebuf, s_infotype[type]); 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; newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE;
traced_data = FALSE; traced_data = FALSE;
break; break;