Message ID | 20241205191736.21503-1-heinrich.schuchardt@canonical.com |
---|---|
State | Accepted |
Commit | d701c6ab4220a3f5e0fdef06720816d67c46f56d |
Delegated to: | Tom Rini |
Headers | show |
Series | [1/1] net: lwip: check if network device is available in do_dhcp | expand |
On 12/5/24 20:17, Heinrich Schuchardt wrote: > eth_get_dev() returns NULL if no network device is available. > Not checking the return value leads to a crash when the device > pointer is dereferenced. > > Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> > --- > net/lwip/dhcp.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c > index 9b882cf5b87..e7d9147455c 100644 > --- a/net/lwip/dhcp.c > +++ b/net/lwip/dhcp.c > @@ -3,6 +3,7 @@ > > #include <command.h> > #include <console.h> > +#include <log.h> > #include <dm/device.h> > #include <linux/delay.h> > #include <linux/errno.h> > @@ -112,10 +113,17 @@ static int dhcp_loop(struct udevice *udev) > int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > { > int ret; > + struct udevice *dev; > > eth_set_current(); > > - ret = dhcp_loop(eth_get_dev()); > + dev = eth_get_dev(); > + if (!dev) { > + log_err("No network device\n"); > + return CMD_RET_FAILURE; > + } > + > + ret = dhcp_loop(dev); > if (ret) > return ret; > Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Thanks,
On Thu, 05 Dec 2024 20:17:36 +0100, Heinrich Schuchardt wrote: > eth_get_dev() returns NULL if no network device is available. > Not checking the return value leads to a crash when the device > pointer is dereferenced. > > Applied to u-boot/master, thanks!
diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c index 9b882cf5b87..e7d9147455c 100644 --- a/net/lwip/dhcp.c +++ b/net/lwip/dhcp.c @@ -3,6 +3,7 @@ #include <command.h> #include <console.h> +#include <log.h> #include <dm/device.h> #include <linux/delay.h> #include <linux/errno.h> @@ -112,10 +113,17 @@ static int dhcp_loop(struct udevice *udev) int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { int ret; + struct udevice *dev; eth_set_current(); - ret = dhcp_loop(eth_get_dev()); + dev = eth_get_dev(); + if (!dev) { + log_err("No network device\n"); + return CMD_RET_FAILURE; + } + + ret = dhcp_loop(dev); if (ret) return ret;
eth_get_dev() returns NULL if no network device is available. Not checking the return value leads to a crash when the device pointer is dereferenced. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> --- net/lwip/dhcp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)