From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil+cisco@kernel.org>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: Re: [PATCH] media: cec: extron-da-hd-4k-plus: add sanity check
Date: Mon, 29 Jun 2026 17:03:52 +0300 [thread overview]
Message-ID: <20260629140352.GA3102371@killaraus.ideasonboard.com> (raw)
In-Reply-To: <362ab4a1-6591-4715-ad1e-956a65ec322c@kernel.org>
Hi Hans,
Thank you for the patch.
On Thu, Jun 18, 2026 at 01:03:19PM +0200, Hans Verkuil wrote:
> Add check to prevent overflowing msg.msg[] in case the incoming data
> is malformed.
>
> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
> ---
> diff --git a/drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c b/drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c
> index 3381d86096a1..3c6ce6f3d93e 100644
> --- a/drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c
> +++ b/drivers/media/cec/usb/extron-da-hd-4k-plus/extron-da-hd-4k-plus.c
> @@ -657,7 +657,8 @@ static void extron_process_received(struct extron_port *port, const char *data)
> if (!port || port->disconnected)
> return;
>
> - if (len < 5 || (len - 2) % 3 || data[len - 2] != '*')
> + if (len < 5 || ((len - 2) / 3 > sizeof(msg.msg)) ||
I think you should use ARRAY_SIZE
> + (len - 2) % 3 || data[len - 2] != '*')
This seems correct, but I think the code would be easier to read and
maintain if you wrote
int len;
/* The last two bytes are ignored because ... */
len = strlen(data) - 2;
/*
* Ensure the data has at least one message, at most the number
* of messages that fit in msg.msg, and no extra bytes.
*/
if (len < 3 || len / 3 > ARRAY_SIZE(msg.msg) || len % 3)
goto malformed;
if (data[len] != '*')
goto malformed;
> goto malformed;
>
> while (*data != '*') {
>
--
Regards,
Laurent Pinchart
prev parent reply other threads:[~2026-06-29 14:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 11:03 [PATCH] media: cec: extron-da-hd-4k-plus: add sanity check Hans Verkuil
2026-06-18 11:16 ` Hans Verkuil
2026-06-29 13:57 ` Sean Young
2026-06-29 14:03 ` Laurent Pinchart [this message]
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=20260629140352.GA3102371@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=hverkuil+cisco@kernel.org \
--cc=linux-media@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