diff options
author | Daniel Stenberg <daniel@haxx.se> | 2008-10-13 22:21:01 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2008-10-13 22:21:01 +0000 |
commit | b7722e7037d87e4afeded8a7317db25875002bc0 (patch) | |
tree | 65b440fc1c172178c2f43d587b8b98354a1da051 /src | |
parent | 6c2167b65fbbc315e57210c8bb982710fb9ddcf2 (diff) |
Prevent the accidental passing along NULL for the cases where the --trace
options don't succeed in opening the target file etc. Detected by coverity.com
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/main.c b/src/main.c index 7d397362c..b547eb5f1 100644 --- a/src/main.c +++ b/src/main.c @@ -3506,6 +3506,11 @@ int my_trace(CURL *handle, curl_infotype type, if(config->trace_stream) output = config->trace_stream; + if(!output) { + warnf(config, "Failed to create/open output"); + return 0; + } + if(config->tracetype == TRACE_PLAIN) { /* * This is the trace look that is similar to what libcurl makes on its @@ -3524,25 +3529,24 @@ int my_trace(CURL *handle, curl_infotype type, for(i=0; i<size-1; i++) { if(data[i] == '\n') { /* LF */ if(!newl) { - fprintf(config->trace_stream, "%s%s ", - timebuf, s_infotype[type]); + fprintf(output, "%s%s ", timebuf, s_infotype[type]); } - fwrite(data+st, i-st+1, 1, config->trace_stream); + fwrite(data+st, i-st+1, 1, output); st = i+1; newl = FALSE; } } if(!newl) - fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]); - fwrite(data+st, i-st+1, 1, config->trace_stream); + fprintf(output, "%s%s ", timebuf, s_infotype[type]); + fwrite(data+st, i-st+1, 1, output); newl = (bool)(size && (data[size-1] != '\n')); traced_data = FALSE; break; case CURLINFO_TEXT: case CURLINFO_HEADER_IN: if(!newl) - fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]); - fwrite(data, size, 1, config->trace_stream); + fprintf(output, "%s%s ", timebuf, s_infotype[type]); + fwrite(data, size, 1, output); newl = (bool)(size && (data[size-1] != '\n')); traced_data = FALSE; break; @@ -3556,11 +3560,10 @@ int my_trace(CURL *handle, curl_infotype type, being shown as the data _is_ shown then just not via this function */ if(!config->isatty || - ((config->trace_stream != stderr) && - (config->trace_stream != stdout))) { + ((output != stderr) && (output != stdout))) { if(!newl) - fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]); - fprintf(config->trace_stream, "[data not shown]\n"); + fprintf(output, "%s%s ", timebuf, s_infotype[type]); + fprintf(output, "[data not shown]\n"); newl = FALSE; traced_data = TRUE; } |