Skip to contentSkip to conversation

media: v4l2: check null return of kmalloc in format_ref_list_p and format_ref_list_b

PATCH In review Kang Chen 2 participants 2 messages Feb 26, 2023 – Mar 13, 2023 Media (V4L/DVB)

lore
Share & tools
lore

Kang Chen

author
#0 lore raw

PATCH 1/1 media: v4l2: check null return of kmalloc in format_ref_list_p and format_ref_list_b

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

---
 drivers/media/v4l2-core/v4l2-h264.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/media/v4l2-core/v4l2-h264.c +6 -0
index 72bd64f65..c7a088882 100644
@@ -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++) {
Signature · 1 line
2.34.1
#1 lore raw

Hi Kang,

Quoted 4 lines · Kang Chen

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

This seems to have been addressed by commit be3ae7cf4326e95bb1d5413b63baabc26f4a1324 that's already in upstream.

Signature · 3 lines
Kind regards,

Sakari Ailus