From: longlong yan <yanlonglong@kylinos.cn>
To: gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
longlong yan <yanlonglong@kylinos.cn>
Subject: [PATCH] usb: ffs-test: add NULL check for malloc in descs_to_legacy
Date: Mon, 17 Aug 2026 14:48:01 +0800 [thread overview]
Message-ID: <20260817064801.797-1-yanlonglong@kylinos.cn> (raw)
In descs_to_legacy(), the return value of malloc() is used without a
NULL check. If malloc() fails, dereferencing the resulting pointer
leads to a NULL pointer dereference. Add a NULL check and return 0 on
failure, consistent with the existing error handling at the start of
the function.
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
---
tools/usb/ffs-test.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index 22b938fbdfb7..5c9281cbbff1 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -293,6 +293,8 @@ static size_t descs_to_legacy(void **legacy, const void *descriptors_v2)
length = sizeof out->header + (descs_end - descs_start);
out = malloc(length);
+ if (!out)
+ return 0;
out->header.magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC);
out->header.length = cpu_to_le32(length);
out->header.fs_count = cpu_to_le32(fs_count);
--
2.43.0
reply other threads:[~2026-08-17 6:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260817064801.797-1-yanlonglong@kylinos.cn \
--to=yanlonglong@kylinos.cn \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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