From: longlong yan <yanlonglong@kylinos.cn>
To: valentina.manea.m@gmail.com, shuah@kernel.org,
gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
longlong yan <yanlonglong@kylinos.cn>
Subject: [PATCH] usbip: add NULL check for calloc in do_standalone_mode
Date: Mon, 17 Aug 2026 14:15:14 +0800 [thread overview]
Message-ID: <20260817061514.765-1-yanlonglong@kylinos.cn> (raw)
Add a NULL check for the return value of calloc() in
do_standalone_mode(). If calloc() fails and returns NULL, the
subsequent access to fds[i].fd would cause a NULL pointer
dereference.
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
tools/usb/usbip/src/usbipd.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index 3e22b651c754..dbc2b48363b2 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -544,6 +544,11 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
dbg("listening on %d address%s", nsockfd, (nsockfd == 1) ? "" : "es");
fds = calloc(nsockfd, sizeof(struct pollfd));
+ if (!fds) {
+ err("calloc for pollfd");
+ usbip_driver_close(driver);
+ return -1;
+ }
for (i = 0; i < nsockfd; i++) {
fds[i].fd = sockfdlist[i];
fds[i].events = POLLIN;
--
2.43.0
next reply other threads:[~2026-08-17 6:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 6:15 longlong yan [this message]
2026-09-22 10:07 ` [PATCH] usbip: add NULL check for calloc in do_standalone_mode Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260817061514.765-1-yanlonglong@kylinos.cn \
--to=yanlonglong@kylinos.cn \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=valentina.manea.m@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox