diff mbox series

nwt: wget: drop Content-Length processing

Message ID 20241105110849.41348-1-jerome.forissier@linaro.org
State Accepted
Commit 385af1b898af7c36db9f2a00341e9ada0d365132
Headers show
Series nwt: wget: drop Content-Length processing | expand

Commit Message

Jerome Forissier Nov. 5, 2024, 11:08 a.m. UTC
We don't do anything with Content-Length except a debug print, and the
strict_strtoul() call is incorrect (it always returns -EINVAL and leaves
content_length to zero due to the presence of trailing characters after
the decimal valuoe of Content-Length). So let's just drop this piece of
code.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 net/wget.c | 13 -------------
 1 file changed, 13 deletions(-)

Comments

Ilias Apalodimas Nov. 11, 2024, 12:47 p.m. UTC | #1
Hi Jerome,

On Tue, 5 Nov 2024 at 13:09, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> We don't do anything with Content-Length except a debug print, and the
> strict_strtoul() call is incorrect (it always returns -EINVAL and leaves
> content_length to zero due to the presence of trailing characters after
> the decimal valuoe of Content-Length). So let's just drop this piece of
> code.
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
>  net/wget.c | 13 -------------
>  1 file changed, 13 deletions(-)
>
> diff --git a/net/wget.c b/net/wget.c
> index 635f82efbb3..361817ace65 100644
> --- a/net/wget.c
> +++ b/net/wget.c
> @@ -26,7 +26,6 @@ static const char bootfile1[] = "GET ";
>  static const char bootfile3[] = " HTTP/1.0\r\n\r\n";
>  static const char http_eom[] = "\r\n\r\n";
>  static const char http_ok[] = "200";
> -static const char content_len[] = "Content-Length";
>  static const char linefeed[] = "\r\n";
>  static struct in_addr web_server_ip;
>  static int our_port;
> @@ -46,7 +45,6 @@ struct pkt_qd {
>  #define PKTQ_SZ (PKTBUFSRX / 4)
>  static struct pkt_qd pkt_q[PKTQ_SZ];
>  static int pkt_q_idx;
> -static unsigned long content_length;
>  static unsigned int packets;
>
>  static unsigned int initial_data_seq_num;
> @@ -251,17 +249,6 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num,
>                                    "wget: Connected Pkt %p hlen %x\n",
>                                    pkt, hlen);
>
> -                       pos = strstr((char *)pkt, content_len);
> -                       if (!pos) {
> -                               content_length = -1;
> -                       } else {
> -                               pos += sizeof(content_len) + 2;
> -                               strict_strtoul(pos, 10, &content_length);
> -                               debug_cond(DEBUG_WGET,
> -                                          "wget: Connected Len %lu\n",
> -                                          content_length);

How much work would it be to fix the parsing properly? We could look
into that value and drop it if the memory is > our available memory

Thanks
/Ilias
> -                       }
> -
>                         net_boot_file_size = 0;
>
>                         if (len > hlen) {
> --
> 2.40.1
>
Tom Rini Nov. 13, 2024, 2:13 p.m. UTC | #2
On Tue, 05 Nov 2024 12:08:49 +0100, Jerome Forissier wrote:

> We don't do anything with Content-Length except a debug print, and the
> strict_strtoul() call is incorrect (it always returns -EINVAL and leaves
> content_length to zero due to the presence of trailing characters after
> the decimal valuoe of Content-Length). So let's just drop this piece of
> code.
> 
> 
> [...]

Applied to u-boot/master, thanks!
Jerome Forissier Nov. 13, 2024, 2:27 p.m. UTC | #3
On 11/11/24 13:47, Ilias Apalodimas wrote:
> Hi Jerome,
> 
> On Tue, 5 Nov 2024 at 13:09, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>> We don't do anything with Content-Length except a debug print, and the
>> strict_strtoul() call is incorrect (it always returns -EINVAL and leaves
>> content_length to zero due to the presence of trailing characters after
>> the decimal valuoe of Content-Length). So let's just drop this piece of
>> code.
>>
>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
>> ---
>>  net/wget.c | 13 -------------
>>  1 file changed, 13 deletions(-)
>>
>> diff --git a/net/wget.c b/net/wget.c
>> index 635f82efbb3..361817ace65 100644
>> --- a/net/wget.c
>> +++ b/net/wget.c
>> @@ -26,7 +26,6 @@ static const char bootfile1[] = "GET ";
>>  static const char bootfile3[] = " HTTP/1.0\r\n\r\n";
>>  static const char http_eom[] = "\r\n\r\n";
>>  static const char http_ok[] = "200";
>> -static const char content_len[] = "Content-Length";
>>  static const char linefeed[] = "\r\n";
>>  static struct in_addr web_server_ip;
>>  static int our_port;
>> @@ -46,7 +45,6 @@ struct pkt_qd {
>>  #define PKTQ_SZ (PKTBUFSRX / 4)
>>  static struct pkt_qd pkt_q[PKTQ_SZ];
>>  static int pkt_q_idx;
>> -static unsigned long content_length;
>>  static unsigned int packets;
>>
>>  static unsigned int initial_data_seq_num;
>> @@ -251,17 +249,6 @@ static void wget_connected(uchar *pkt, unsigned int tcp_seq_num,
>>                                    "wget: Connected Pkt %p hlen %x\n",
>>                                    pkt, hlen);
>>
>> -                       pos = strstr((char *)pkt, content_len);
>> -                       if (!pos) {
>> -                               content_length = -1;
>> -                       } else {
>> -                               pos += sizeof(content_len) + 2;
>> -                               strict_strtoul(pos, 10, &content_length);
>> -                               debug_cond(DEBUG_WGET,
>> -                                          "wget: Connected Len %lu\n",
>> -                                          content_length);
> 
> How much work would it be to fix the parsing properly? We could look
> into that value and drop it if the memory is > our available memory

TBH I have not looked into it. This is the legacy stack; lwIP does
decode and handle the content length properly AFAICT.

Regards,
diff mbox series

Patch

diff --git a/net/wget.c b/net/wget.c
index 635f82efbb3..361817ace65 100644
--- a/net/wget.c
+++ b/net/wget.c
@@ -26,7 +26,6 @@  static const char bootfile1[] = "GET ";
 static const char bootfile3[] = " HTTP/1.0\r\n\r\n";
 static const char http_eom[] = "\r\n\r\n";
 static const char http_ok[] = "200";
-static const char content_len[] = "Content-Length";
 static const char linefeed[] = "\r\n";
 static struct in_addr web_server_ip;
 static int our_port;
@@ -46,7 +45,6 @@  struct pkt_qd {
 #define PKTQ_SZ (PKTBUFSRX / 4)
 static struct pkt_qd pkt_q[PKTQ_SZ];
 static int pkt_q_idx;
-static unsigned long content_length;
 static unsigned int packets;
 
 static unsigned int initial_data_seq_num;
@@ -251,17 +249,6 @@  static void wget_connected(uchar *pkt, unsigned int tcp_seq_num,
 				   "wget: Connected Pkt %p hlen %x\n",
 				   pkt, hlen);
 
-			pos = strstr((char *)pkt, content_len);
-			if (!pos) {
-				content_length = -1;
-			} else {
-				pos += sizeof(content_len) + 2;
-				strict_strtoul(pos, 10, &content_length);
-				debug_cond(DEBUG_WGET,
-					   "wget: Connected Len %lu\n",
-					   content_length);
-			}
-
 			net_boot_file_size = 0;
 
 			if (len > hlen) {