mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usbip: add NULL check for calloc in usbip_exported_device_new
@ 2026-08-17  6:06 longlong yan
  2026-09-22 10:04 ` Shuah Khan
  0 siblings, 1 reply; 2+ messages in thread
From: longlong yan @ 2026-08-17  6:06 UTC (permalink / raw)
  To: valentina.manea.m, shuah, gregkh; +Cc: linux-usb, linux-kernel, longlong yan

Add a NULL check for the return value of calloc() in
usbip_exported_device_new(). If calloc() fails and returns NULL,
the subsequent dereference of edev->sudev would cause a NULL
pointer dereference.

Also fix the error path at the 'err' label to check edev before
dereferencing edev->sudev. Without this fix, if calloc() fails and
jumps to 'err', the code would dereference NULL when checking
edev->sudev.

Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
 tools/usb/usbip/libsrc/usbip_host_common.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
index 01599cb2fa7b..94762bc282eb 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.c
+++ b/tools/usb/usbip/libsrc/usbip_host_common.c
@@ -71,6 +71,8 @@ struct usbip_exported_device *usbip_exported_device_new(
 	int i;
 
 	edev = calloc(1, sizeof(struct usbip_exported_device));
+	if (!edev)
+		goto err;
 
 	edev->sudev =
 		udev_device_new_from_syspath(udev_context, sdevpath);
@@ -107,7 +109,7 @@ struct usbip_exported_device *usbip_exported_device_new(
 
 	return edev;
 err:
-	if (edev->sudev)
+	if (edev && edev->sudev)
 		udev_device_unref(edev->sudev);
 	if (edev)
 		free(edev);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-22 10:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-17  6:06 [PATCH] usbip: add NULL check for calloc in usbip_exported_device_new longlong yan
2026-09-22 10:04 ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®