[PATCH] USB: Fix NULLPTR dereference when serial# is unset

Marek Vasut marex at denx.de
Tue Jan 28 00:22:47 CET 2025


On 1/28/25 12:12 AM, Michael wrote:
> The problem can be reproduced with U-Boot's sandbox with the default config.
> Then, run the following commands at the shell:
> Hit any key to stop autoboot:  0
> => env set serial# test
> => env default -f serial#
> at which point the program will crash.
Maybe the fix needs to be one level higher ?

diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c
index 631969b3405..f2540eb6ded 100644
--- a/drivers/usb/gadget/g_dnl.c
+++ b/drivers/usb/gadget/g_dnl.c
@@ -207,7 +207,8 @@ void g_dnl_clear_detach(void)
  static int on_serialno(const char *name, const char *value, enum 
env_op op,
                 int flags)
  {
-       g_dnl_set_serialnumber((char *)value);
+       if (value)
+               g_dnl_set_serialnumber((char *)value);
         return 0;
  }
  U_BOOT_ENV_CALLBACK(serialno, on_serialno);


More information about the U-Boot mailing list