Skip to contentSkip to conversation

usb: gadget: g_dnl: Fix NULLPTR dereference

PATCH Superseded Michael Ferolito 1 participant 1 message Jan 28, 2025 USB

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 usb: gadget: g_dnl: Fix NULLPTR dereference

The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash.
In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal.
This simple check is enough to fix it

Cc Marek Vasut <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Kyungmin Park <[email protected]>
---
 drivers/usb/gadget/g_dnl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/g_dnl.c +2 -1
index 631969b340..f2540eb6de 100644
@@ -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);
Signature · 1 line
2.48.1