diff options
author | Kamil Dudka <kdudka@redhat.com> | 2018-10-15 16:03:46 +0200 |
---|---|---|
committer | Kamil Dudka <kdudka@redhat.com> | 2018-10-17 09:15:05 +0200 |
commit | 6b6ba1dc29857f5eb4c31fed3d63619fea99d5f4 (patch) | |
tree | 4605f20e648ac673201e2e977a7a0fb973ac0beb /src | |
parent | 21ac06888f9a86272e2a9dc38b9b24ed80050c1c (diff) | |
download | curl-6b6ba1dc29857f5eb4c31fed3d63619fea99d5f4.tar.gz |
tool_cb_hdr: handle failure of rename()
Detected by Coverity.
Closes #3140
Reviewed-by: Jay Satiro
Diffstat (limited to 'src')
-rw-r--r-- | src/tool_cb_hdr.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c index 983258cee..7a7a836c4 100644 --- a/src/tool_cb_hdr.c +++ b/src/tool_cb_hdr.c @@ -132,15 +132,24 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) filename = parse_filename(p, len); if(filename) { if(outs->stream) { + int rc; /* already opened and possibly written to */ if(outs->fopened) fclose(outs->stream); outs->stream = NULL; /* rename the initial file name to the new file name */ - rename(outs->filename, filename); + rc = rename(outs->filename, filename); + if(rc != 0) { + warnf(outs->config->global, "Failed to rename %s -> %s: %s\n", + outs->filename, filename, strerror(errno)); + } if(outs->alloc_filename) - free(outs->filename); + Curl_safefree(outs->filename); + if(rc != 0) { + free(filename); + return failure; + } } outs->is_cd_filename = TRUE; outs->s_isreg = TRUE; |