mirror of https://github.com/moparisthebest/curl
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
This commit is contained in:
parent
6c2167b65f
commit
b7722e7037
25
src/main.c
25
src/main.c
|
@ -3506,6 +3506,11 @@ int my_trace(CURL *handle, curl_infotype type,
|
||||||
if(config->trace_stream)
|
if(config->trace_stream)
|
||||||
output = config->trace_stream;
|
output = config->trace_stream;
|
||||||
|
|
||||||
|
if(!output) {
|
||||||
|
warnf(config, "Failed to create/open output");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if(config->tracetype == TRACE_PLAIN) {
|
if(config->tracetype == TRACE_PLAIN) {
|
||||||
/*
|
/*
|
||||||
* This is the trace look that is similar to what libcurl makes on its
|
* 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++) {
|
for(i=0; i<size-1; i++) {
|
||||||
if(data[i] == '\n') { /* LF */
|
if(data[i] == '\n') { /* LF */
|
||||||
if(!newl) {
|
if(!newl) {
|
||||||
fprintf(config->trace_stream, "%s%s ",
|
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||||
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;
|
st = i+1;
|
||||||
newl = FALSE;
|
newl = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!newl)
|
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);
|
||||||
newl = (bool)(size && (data[size-1] != '\n'));
|
newl = (bool)(size && (data[size-1] != '\n'));
|
||||||
traced_data = FALSE;
|
traced_data = FALSE;
|
||||||
break;
|
break;
|
||||||
case CURLINFO_TEXT:
|
case CURLINFO_TEXT:
|
||||||
case CURLINFO_HEADER_IN:
|
case CURLINFO_HEADER_IN:
|
||||||
if(!newl)
|
if(!newl)
|
||||||
fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
|
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||||
fwrite(data, size, 1, config->trace_stream);
|
fwrite(data, size, 1, output);
|
||||||
newl = (bool)(size && (data[size-1] != '\n'));
|
newl = (bool)(size && (data[size-1] != '\n'));
|
||||||
traced_data = FALSE;
|
traced_data = FALSE;
|
||||||
break;
|
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
|
being shown as the data _is_ shown then just not via this
|
||||||
function */
|
function */
|
||||||
if(!config->isatty ||
|
if(!config->isatty ||
|
||||||
((config->trace_stream != stderr) &&
|
((output != stderr) && (output != stdout))) {
|
||||||
(config->trace_stream != stdout))) {
|
|
||||||
if(!newl)
|
if(!newl)
|
||||||
fprintf(config->trace_stream, "%s%s ", timebuf, s_infotype[type]);
|
fprintf(output, "%s%s ", timebuf, s_infotype[type]);
|
||||||
fprintf(config->trace_stream, "[data not shown]\n");
|
fprintf(output, "[data not shown]\n");
|
||||||
newl = FALSE;
|
newl = FALSE;
|
||||||
traced_data = TRUE;
|
traced_data = TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue