public inbox for [email protected]
 help / color / mirror / Atom feed
From: Chenyuan Mi <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
	[email protected], Chenyuan Mi <[email protected]>
Subject: [PATCH] tools/io_uring: Fix missing check for return value of malloc()
Date: Thu, 15 Jun 2023 05:53:50 -0700	[thread overview]
Message-ID: <[email protected]> (raw)

The malloc() function may return NULL when it fails,
which may cause null pointer deference. Add Null 
check for return value of malloc().

Found by our static analysis tool.

Signed-off-by: Chenyuan Mi <[email protected]>
---
 tools/io_uring/io_uring-bench.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/io_uring/io_uring-bench.c b/tools/io_uring/io_uring-bench.c
index 7703f0118385..a7fedfdb9b84 100644
--- a/tools/io_uring/io_uring-bench.c
+++ b/tools/io_uring/io_uring-bench.c
@@ -560,6 +560,11 @@ int main(int argc, char *argv[])
 	pthread_create(&s->thread, NULL, submitter_fn, s);
 
 	fdepths = malloc(8 * s->nr_files);
+	if (!fdepths) {
+		printf("malloc failed");
+		return 1;
+	}
+
 	reap = calls = done = 0;
 	do {
 		unsigned long this_done = 0;
-- 
2.17.1


             reply	other threads:[~2023-06-15 12:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 12:53 Chenyuan Mi [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-06-15 12:50 [PATCH] tools/io_uring: Fix missing check for return value of malloc() Chenyuan Mi
2023-06-15 13:00 ` Ammar Faizi
2023-06-15 13:13   ` Jens Axboe
     [not found]     ` <[email protected]>
2023-06-15 13:37       ` [PATCH] tools/io uring: " Jens Axboe

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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