Skip to contentSkip to conversation

net: lwip: fix dhcp_loop()

PATCH In review Jerome Forissier 3 participants 4 messages Nov 22, 2024 – Nov 23, 2024 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: lwip: fix dhcp_loop()

The local variables ipstr, maskstr and gwstr in static function dhcp_loop() cannot be pointers to read-only data, since they may be written to in case the device index is > 0. Therefore make them char arrays allocated on the stack.

Reported-by Ilias Apalodimas <ilias.apalodimas at linaro.org>
---
 net/lwip/dhcp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/lwip/dhcp.c +3 -3
index 23b56226921..bfc72ca6c57 100644
@@ -27,9 +27,9 @@ static void call_lwip_dhcp_fine_tmr(void *ctx)
 
 static int dhcp_loop(struct udevice *udev)
 {
-	char *ipstr = "ipaddr\0\0";
-	char *maskstr = "netmask\0\0";
-	char *gwstr = "gatewayip\0\0";
+	char ipstr[] = "ipaddr\0\0";
+	char maskstr[] = "netmask\0\0";
+	char gwstr[] = "gatewayip\0\0";
 	unsigned long start;
 	struct netif *netif;
 	struct dhcp *dhcp;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jerome Forissier

The local variables ipstr, maskstr and gwstr in static function dhcp_loop() cannot be pointers to read-only data, since they may be written to in case the device index is > 0. Therefore make them char arrays allocated on the stack.

Reported-by Ilias Apalodimas <ilias.apalodimas at linaro.org>

@
But I guess we can fix that up during merging

Quoted 25 lines
---
 net/lwip/dhcp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/lwip/dhcp.c +3 -4
index 23b56226921..bfc72ca6c57 100644
@@ -27,9 +27,9 @@ static void call_lwip_dhcp_fine_tmr(void *ctx)
 
 static int dhcp_loop(struct udevice *udev)
 {
-       char *ipstr = "ipaddr\0\0";
-       char *maskstr = "netmask\0\0";
-       char *gwstr = "gatewayip\0\0";
+       char ipstr[] = "ipaddr\0\0";
+       char maskstr[] = "netmask\0\0";
+       char gwstr[] = "gatewayip\0\0";
        unsigned long start;
        struct netif *netif;
        struct dhcp *dhcp;
--

2.43.0

#2 lore raw
Quoted 8 lines · Ilias Apalodimas
Quoted 6 lines · Jerome Forissier

The local variables ipstr, maskstr and gwstr in static function dhcp_loop() cannot be pointers to read-only data, since they may be written to in case the device index is > 0. Therefore make them char arrays allocated on the stack.

Quoted 4 lines
Quoted 1 line
Reported-by Ilias Apalodimas <ilias.apalodimas at linaro.org>

@
But I guess we can fix that up during merging

Sorry about that. Bad copy/paste from the ML web page ;)

Signature · 1 line
Jerome
Quoted 28 lines
Quoted 25 lines
---
 net/lwip/dhcp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/lwip/dhcp.c +3 -4
index 23b56226921..bfc72ca6c57 100644
@@ -27,9 +27,9 @@ static void call_lwip_dhcp_fine_tmr(void *ctx)
 
 static int dhcp_loop(struct udevice *udev)
 {
-       char *ipstr = "ipaddr\0\0";
-       char *maskstr = "netmask\0\0";
-       char *gwstr = "gatewayip\0\0";
+       char ipstr[] = "ipaddr\0\0";
+       char maskstr[] = "netmask\0\0";
+       char gwstr[] = "gatewayip\0\0";
        unsigned long start;
        struct netif *netif;
        struct dhcp *dhcp;
--

2.43.0

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

The local variables ipstr, maskstr and gwstr in static function dhcp_loop() cannot be pointers to read-only data, since they may be written to in case the device index is > 0. Therefore make them char arrays allocated on the stack.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom