From: Daniel Stenberg Date: Mon, 23 Nov 2009 13:56:45 +0000 (+0000) Subject: - Bjorn Augustsson reported a bug which made curl not report any problems even X-Git-Tag: curl-7_20_0~321 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1fddcb3f887c487a22b38082e651d24ae5865db2;p=thirdparty%2Fcurl.git - Bjorn Augustsson reported a bug which made curl not report any problems even though it failed to write a very small download to disk (done in a single fwrite call). It turned out to be because fwrite() returned success, but there was insufficient error-checking for the fclose() call which tricked curl to believe things were fine. --- diff --git a/CHANGES b/CHANGES index 83fa0c1cf1..9bdcb06608 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,14 @@ Changelog + +Daniel Stenberg (23 Nov 2009) +- Bjorn Augustsson reported a bug which made curl not report any problems even + though it failed to write a very small download to disk (done in a single + fwrite call). It turned out to be because fwrite() returned success, but + there was insufficient error-checking for the fclose() call which tricked + curl to believe things were fine. + Daniel Stenberg (20 Nov 2009) - Constantine Sapuntzakis identified a write after close, as the sockets were closed by libcurl before the SSL lib were shutdown and they may write to its diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 64e84e687f..f4712133c7 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -25,6 +25,7 @@ This release includes the following bugfixes: o never-pruned DNS cached entries o HTTP proxy tunnel re-used connection even if tunnel got disabled o SSL lib post-close write + o curl failed to report write errors for tiny failed downloads This release includes the following known bugs: @@ -35,6 +36,6 @@ advice from friends like these: Yang Tse, Kamil Dudka, Christian Schmitz, Constantine Sapuntzakis, Marco Maggi, Camille Moncelier, Claes Jakobsson, Kevin Baughman, - Marc Kleine-Budde, Jad Chamcham + Marc Kleine-Budde, Jad Chamcham, Bjorn Augustsson Thanks! (and sorry if I forgot to mention someone) diff --git a/src/main.c b/src/main.c index fed1e1fccc..b9ac7adb4a 100644 --- a/src/main.c +++ b/src/main.c @@ -3316,9 +3316,15 @@ static size_t my_fwrite(void *buffer, size_t sz, size_t nmemb, void *stream) curl_easy_pause(config->easy, CURLPAUSE_CONT); } - if(config->nobuffer) + if(config->nobuffer) { /* disable output buffering */ - fflush(out->stream); + rc = fflush(out->stream); + if(rc) { + /* return a value that isn't the same as sz * nmemb */ + rc = (0 == (sz * nmemb)) ? 1 : 0; + return rc; /* failure */ + } + } return rc; } @@ -5170,8 +5176,14 @@ show_error: } } - if (outfile && !curlx_strequal(outfile, "-") && outs.stream) - fclose(outs.stream); + if (outfile && !curlx_strequal(outfile, "-") && outs.stream) { + int rc = fclose(outs.stream); + if(!res && rc) { + /* something went wrong in the writing process */ + res = CURLE_WRITE_ERROR; + fprintf(config->errors, "(%s) Failed writing body\n", res); + } + } #ifdef HAVE_UTIME /* Important that we set the time _after_ the file has been