public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: v4l2: check null return of kmalloc in format_ref_list_p and format_ref_list_b
@ 2023-02-26  6:50 Kang Chen
  2023-03-13 11:10 ` Sakari Ailus
  0 siblings, 1 reply; 2+ messages in thread
From: Kang Chen @ 2023-02-26  6:50 UTC (permalink / raw)
  To: mchehab; +Cc: linux-media, linux-kernel, Kang Chen

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


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

end of thread, other threads:[~2023-03-13 11:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-26  6:50 [PATCH] media: v4l2: check null return of kmalloc in format_ref_list_p and format_ref_list_b Kang Chen
2023-03-13 11:10 ` Sakari Ailus

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