diff mbox series

net: lwip: fix dhcp_loop()

Message ID 20241122123558.74702-1-jerome.forissier@linaro.org
State Accepted
Commit 8c95d84b39fc0886a4417c5ddefc2ea05217c0ac
Headers show
Series net: lwip: fix dhcp_loop() | expand

Commit Message

Jerome Forissier Nov. 22, 2024, 12:35 p.m. UTC
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>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 net/lwip/dhcp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Ilias Apalodimas Nov. 22, 2024, 12:37 p.m. UTC | #1
On Fri, 22 Nov 2024 at 14:36, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> 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

Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
>  net/lwip/dhcp.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c
> index 23b56226921..bfc72ca6c57 100644
> --- a/net/lwip/dhcp.c
> +++ b/net/lwip/dhcp.c
> @@ -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
>
Jerome Forissier Nov. 22, 2024, 12:43 p.m. UTC | #2
On 11/22/24 13:37, Ilias Apalodimas wrote:
> On Fri, 22 Nov 2024 at 14:36, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>> 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

Sorry about that. Bad copy/paste from the ML web page ;)
Tom Rini Nov. 23, 2024, 2:42 a.m. UTC | #3
On Fri, Nov 22, 2024 at 01:35:29PM +0100, Jerome Forissier wrote:

> 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@linaro.org>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c
index 23b56226921..bfc72ca6c57 100644
--- a/net/lwip/dhcp.c
+++ b/net/lwip/dhcp.c
@@ -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;