[git commit] wget: detect when the length of received file is less than advertised

Denys Vlasenko vda.linux at googlemail.com
Mon Jan 21 12:53:26 UTC 2019


commit: https://git.busybox.net/busybox/commit/?id=9b313ddcd8c24361b2e8fb4f0f11459436be112f
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
retrieve_file_data                                   579     596     +17

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/wget.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/networking/wget.c b/networking/wget.c
index 3f3d3a0c9..fa4d21afd 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");


More information about the busybox-cvs mailing list