From: Igor Velkov <[email protected]>

lwIP passes 0xffffffff as the content length when a reply has no usable
Content-Length header. With check_buffer_size set, wget compares that
value with the buffer size and refuses the download whenever the
buffer is smaller than 4 GiB, before any data arrives.

Skip the check when the length is unknown, as the legacy wget does.
store_block() still stops a download that outgrows the buffer.

Fixes: 1327c2a8d651 ("net/lwip: wget: integrate struct wget_info into wget 
code")
Signed-off-by: Igor Velkov <[email protected]>
---
 net/lwip/wget.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/lwip/wget.c b/net/lwip/wget.c
index 96ee600c5e1..615ea035a28 100644
--- a/net/lwip/wget.c
+++ b/net/lwip/wget.c
@@ -6,6 +6,7 @@
 #include <display_options.h>
 #include <efi_loader.h>
 #include <env.h>
+#include <limits.h>
 #include <linux/kconfig.h>
 #include <lwip/apps/http_client.h>
 #include "lwip/altcp_tls.h"
@@ -285,7 +286,9 @@ static err_t httpc_headers_done_cb(httpc_state_t 
*connection, void *arg, struct
 
        wget_lwip_fill_info(hdr, hdr_len, content_len);
 
-       if (wget_info->check_buffer_size && (ulong)content_len > 
wget_info->buffer_size)
+       /* lwIP passes U32_MAX when the reply has no usable Content-Length */
+       if (wget_info->check_buffer_size && content_len != U32_MAX &&
+           (ulong)content_len > wget_info->buffer_size)
                return ERR_BUF;
 
        ctx->content_len = content_len;

-- 
2.43.0


Reply via email to