diff options
author | Daniel Stenberg <daniel@haxx.se> | 2017-09-20 12:03:44 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2017-09-20 12:03:44 +0200 |
commit | 299896ca0963a79d5ec4de8ca83922c48f16f1bb (patch) | |
tree | f2054abb394396353d3afc19da3f7fa918f6bfbf | |
parent | 1e548f77847ac51a7054adef24825624fb73b219 (diff) |
curl: check fseek() return code and bail on error
Detected by coverity. CID 1418137.
-rw-r--r-- | src/tool_operate.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c index f32558af5..6dd05dbf4 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1668,6 +1668,7 @@ static CURLcode operate_do(struct GlobalConfig *global, retry_sleep = RETRY_SLEEP_MAX; } if(outs.bytes && outs.filename && outs.stream) { + int rc; /* We have written data to a output file, we truncate file */ if(!global->mute) @@ -1688,14 +1689,21 @@ static CURLcode operate_do(struct GlobalConfig *global, } /* now seek to the end of the file, the position where we just truncated the file in a large file-safe way */ - fseek(outs.stream, 0, SEEK_END); + rc = fseek(outs.stream, 0, SEEK_END); #else /* ftruncate is not available, so just reposition the file to the location we would have truncated it. This won't work properly with large files on 32-bit systems, but most of those will have ftruncate. */ - fseek(outs.stream, (long)outs.init, SEEK_SET); + rc = fseek(outs.stream, (long)outs.init, SEEK_SET); #endif + if(rc) { + if(!global->mute) + fprintf(global->errors, + "failed seeking to end of file, exiting\n"); + result = CURLE_WRITE_ERROR; + goto quit_urls; + } outs.bytes = 0; /* clear for next round */ } continue; /* curl_easy_perform loop */ |