diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-08-28 21:55:22 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-08-28 21:55:22 +0000 |
commit | 83e4a5bccf3b06f9b2cbd708d48d1ea0602297c6 (patch) | |
tree | 459bcd4f0aca9d75f883b91130fd4236e06b6d5c | |
parent | 8b96b7169d0af8c1b7ede14755a8bd4492f894d0 (diff) | |
download | busybox-w32-83e4a5bccf3b06f9b2cbd708d48d1ea0602297c6.tar.gz busybox-w32-83e4a5bccf3b06f9b2cbd708d48d1ea0602297c6.tar.bz2 busybox-w32-83e4a5bccf3b06f9b2cbd708d48d1ea0602297c6.zip |
"When the filesize is known from content-length header, safe_fread is
always told to read sizeof(buf). This waits until the underlying
fread() to time-out for the last part of the downloaded body. Fix
this by sending the number of remaining bytes to read when known." -
junkio@
I reworked the logic in his patch
-rw-r--r-- | networking/wget.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/networking/wget.c b/networking/wget.c index a9ead7fc2..586a7e0d4 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -481,25 +481,30 @@ read_response: if (fgets(buf, sizeof(buf), sfp) == NULL) | |||
481 | progressmeter(-1); | 481 | progressmeter(-1); |
482 | #endif | 482 | #endif |
483 | do { | 483 | do { |
484 | while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) { | 484 | while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, (chunked || !got_clen || (filesize > sizeof(buf)) ? sizeof(buf) : filesize), dfp)) > 0) { |
485 | if (safe_fwrite(buf, 1, n, output) != n) | 485 | if (safe_fwrite(buf, 1, n, output) != n) { |
486 | bb_perror_msg_and_die("write error"); | 486 | bb_perror_msg_and_die("write error"); |
487 | } | ||
487 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 488 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |
488 | statbytes+=n; | 489 | statbytes+=n; |
489 | #endif | 490 | #endif |
490 | if (got_clen) | 491 | if (got_clen) { |
491 | filesize -= n; | 492 | filesize -= n; |
492 | } | 493 | } |
494 | } | ||
493 | 495 | ||
494 | if (chunked) { | 496 | if (chunked) { |
495 | safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */ | 497 | safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */ |
496 | safe_fgets(buf, sizeof(buf), dfp); | 498 | safe_fgets(buf, sizeof(buf), dfp); |
497 | filesize = strtol(buf, (char **) NULL, 16); | 499 | filesize = strtol(buf, (char **) NULL, 16); |
498 | if (filesize==0) chunked = 0; /* all done! */ | 500 | if (filesize==0) { |
501 | chunked = 0; /* all done! */ | ||
502 | } | ||
499 | } | 503 | } |
500 | 504 | ||
501 | if (n == 0 && ferror(dfp)) | 505 | if (n == 0 && ferror(dfp)) { |
502 | bb_perror_msg_and_die("network read error"); | 506 | bb_perror_msg_and_die("network read error"); |
507 | } | ||
503 | } while (chunked); | 508 | } while (chunked); |
504 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR | 509 | #ifdef CONFIG_FEATURE_WGET_STATUSBAR |
505 | if (quiet_flag==FALSE) | 510 | if (quiet_flag==FALSE) |
@@ -811,7 +816,7 @@ progressmeter(int flag) | |||
811 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 816 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
812 | * SUCH DAMAGE. | 817 | * SUCH DAMAGE. |
813 | * | 818 | * |
814 | * $Id: wget.c,v 1.54 2003/07/22 08:56:51 andersen Exp $ | 819 | * $Id: wget.c,v 1.55 2003/08/28 21:55:22 bug1 Exp $ |
815 | */ | 820 | */ |
816 | 821 | ||
817 | 822 | ||
@@ -823,6 +828,3 @@ c-basic-offset: 4 | |||
823 | tab-width: 4 | 828 | tab-width: 4 |
824 | End: | 829 | End: |
825 | */ | 830 | */ |
826 | |||
827 | |||
828 | |||