Skip to contentSkip to conversation

nwt: wget: drop Content-Length processing

PATCH In review Jerome Forissier 3 participants 4 messages Nov 5, 2024 – Nov 13, 2024 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nwt: wget: drop Content-Length processing

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.

---
 net/wget.c | 13 -------------
 1 file changed, 13 deletions(-)
net/wget.c +0 -13
index 635f82efbb3..361817ace65 100644
@@ -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) {
Signature · 1 line
2.40.1
#1 lore raw

Hi Jerome,

Quoted 35 lines · Jerome Forissier

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.

---
 net/wget.c | 13 -------------
 1 file changed, 13 deletions(-)
net/wget.c +0 -2
index 635f82efbb3..361817ace65 100644
@@ -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);

net/wget.c static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, · line 262

Quoted 10 lines
net/wget.c +0 -9
 
-                       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

Quoted 8 lines
net/wget.c +0 -3
-                       }
-
                        net_boot_file_size = 0;
 
                        if (len > hlen) {
--

2.40.1

#2 lore raw
Quoted 40 lines · Ilias Apalodimas

Hi Jerome,

Quoted 36 lines · Jerome Forissier

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.

---
 net/wget.c | 13 -------------
 1 file changed, 13 deletions(-)
net/wget.c +0 -2
index 635f82efbb3..361817ace65 100644
@@ -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);
 
Quoted 12 lines

net/wget.c static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, · line 262

Quoted 9 lines
net/wget.c +0 -9
-                       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,

Signature · 1 line
 Jerome
Quoted 11 lines

Thanks
/Ilias

Quoted 8 lines
net/wget.c +0 -3
-                       }
-
                        net_boot_file_size = 0;
 
                        if (len > hlen) {
--

2.40.1

#3 lore raw
In reply to Jerome Forissier
Quoted 8 lines · Jerome Forissier

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!

Signature · 1 line
Tom