All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kang Chen <void0red@gmail.com>
To: mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Kang Chen <void0red@gmail.com>
Subject: [PATCH] media: v4l2: check null return of kmalloc in format_ref_list_p and format_ref_list_b
Date: Sun, 26 Feb 2023 14:50:11 +0800	[thread overview]
Message-ID: <20230226065011.2688452-1-void0red@gmail.com> (raw)

kmalloc may fails, *out_str might be null and will cause
illegal address access later.

Signed-off-by: Kang Chen <void0red@gmail.com>
---
 drivers/media/v4l2-core/v4l2-h264.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-h264.c b/drivers/media/v4l2-core/v4l2-h264.c
index 72bd64f65..c7a088882 100644
--- a/drivers/media/v4l2-core/v4l2-h264.c
+++ b/drivers/media/v4l2-core/v4l2-h264.c
@@ -306,6 +306,9 @@ static const char *format_ref_list_p(const struct v4l2_h264_reflist_builder *bui
 
 	*out_str = kmalloc(tmp_str_size, GFP_KERNEL);
 
+	if (!*out_str)
+		return "NOMEM";
+
 	n += snprintf(*out_str + n, tmp_str_size - n, "|");
 
 	for (i = 0; i < builder->num_valid; i++) {
@@ -344,6 +347,9 @@ static const char *format_ref_list_b(const struct v4l2_h264_reflist_builder *bui
 
 	*out_str = kmalloc(tmp_str_size, GFP_KERNEL);
 
+	if (!*out_str)
+		return "NOMEM";
+
 	n += snprintf(*out_str + n, tmp_str_size - n, "|");
 
 	for (i = 0; i < builder->num_valid; i++) {
-- 
2.34.1


             reply	other threads:[~2023-02-26  6:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-26  6:50 Kang Chen [this message]
2023-03-13 11:10 ` [PATCH] media: v4l2: check null return of kmalloc in format_ref_list_p and format_ref_list_b Sakari Ailus

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=20230226065011.2688452-1-void0red@gmail.com \
    --to=void0red@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.