diff options
author | Denys Vlasenko | 2019-01-21 13:53:26 +0100 |
---|---|---|
committer | Denys Vlasenko | 2019-01-21 13:53:26 +0100 |
commit | 9b313ddcd8c24361b2e8fb4f0f11459436be112f (patch) | |
tree | 31838f3f1892a0486d1224a63908d1e99e22fa62 /networking | |
parent | 4906faafab9760bd2d3ed1c6eb11def9efdc438c (diff) | |
download | busybox-9b313ddcd8c24361b2e8fb4f0f11459436be112f.zip busybox-9b313ddcd8c24361b2e8fb4f0f11459436be112f.tar.gz |
wget: detect when the length of received file is less than advertised
function old new delta
retrieve_file_data 579 596 +17
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r-- | networking/wget.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/networking/wget.c b/networking/wget.c index 3f3d3a0..fa4d21a 100644 --- a/networking/wget.c +++ b/networking/wget.c @@ -248,7 +248,7 @@ struct globals { * With 512 byte buffer, it was measured to be * an order of magnitude slower than with big one. */ - char wget_buf[CONFIG_FEATURE_COPYBUF_KB*1024] ALIGNED(sizeof(long)); + char wget_buf[CONFIG_FEATURE_COPYBUF_KB*1024] ALIGNED(16); } FIX_ALIASING; #define G (*ptr_to_globals) #define INIT_G() do { \ @@ -388,9 +388,6 @@ static void set_alarm(void) * is_ip_address() attempts to verify whether or not a string * contains an IPv4 or IPv6 address (vs. an FQDN). The result * of inet_pton() can be used to determine this. - * - * TODO add proper error checking when inet_pton() returns -1 - * (some form of system error has occurred, and errno is set) */ static int is_ip_address(const char *string) { @@ -1012,6 +1009,15 @@ static void NOINLINE retrieve_file_data(FILE *dfp) */ } + /* Draw full bar and free its resources */ + G.chunked = 0; /* makes it show 100% even for chunked download */ + G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ + progress_meter(PROGRESS_END); + if (G.content_len != 0) { + bb_perror_msg_and_die("connection closed prematurely"); + /* GNU wget says "DATE TIME (NN MB/s) - Connection closed at byte NNN. Retrying." */ + } + /* If -c failed, we restart from the beginning, * but we do not truncate file then, we do it only now, at the end. * This lets user to ^C if his 99% complete 10 GB file download @@ -1023,10 +1029,6 @@ static void NOINLINE retrieve_file_data(FILE *dfp) ftruncate(G.output_fd, pos); } - /* Draw full bar and free its resources */ - G.chunked = 0; /* makes it show 100% even for chunked download */ - G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ - progress_meter(PROGRESS_END); if (!(option_mask32 & WGET_OPT_QUIET)) { if (G.output_fd == 1) fprintf(stderr, "written to stdout\n"); |