linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: v4l2-ctrls: Fix off-by-one error in integer menu control check
@ 2022-09-26 16:31 Laurent Pinchart
  2022-09-26 16:40 ` Sakari Ailus
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Pinchart @ 2022-09-26 16:31 UTC (permalink / raw)
  To: linux-media
  Cc: linux-renesas-soc, Hans Verkuil, Sakari Ailus,
	Sylwester Nawrocki, Laurent Pinchart

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

The V4L2 API defines the maximum value for an integer menu control as
the number of elements minus one. The v4l2_ctrl_new_std_menu() validates
this constraint with an off-by-one error. Fix it.

Fixes: d1e9b7c12b74 ("[media] V4L: Add support for integer menu controls with standard menu items")
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-ctrls-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 1f85828d6694..322f9f715b65 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -1762,7 +1762,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
 	else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
 		qmenu_int = v4l2_ctrl_get_int_menu(id, &qmenu_int_len);
 
-	if ((!qmenu && !qmenu_int) || (qmenu_int && max > qmenu_int_len)) {
+	if ((!qmenu && !qmenu_int) || (qmenu_int && max >= qmenu_int_len)) {
 		handler_set_err(hdl, -EINVAL);
 		return NULL;
 	}
-- 
Regards,

Laurent Pinchart


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

* Re: [PATCH] media: v4l2-ctrls: Fix off-by-one error in integer menu control check
  2022-09-26 16:31 [PATCH] media: v4l2-ctrls: Fix off-by-one error in integer menu control check Laurent Pinchart
@ 2022-09-26 16:40 ` Sakari Ailus
  0 siblings, 0 replies; 2+ messages in thread
From: Sakari Ailus @ 2022-09-26 16:40 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, linux-renesas-soc, Hans Verkuil, Sylwester Nawrocki,
	Laurent Pinchart

Hi Laurent,

On Mon, Sep 26, 2022 at 07:31:51PM +0300, Laurent Pinchart wrote:
> From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> 
> The V4L2 API defines the maximum value for an integer menu control as
> the number of elements minus one. The v4l2_ctrl_new_std_menu() validates
> this constraint with an off-by-one error. Fix it.
> 
> Fixes: d1e9b7c12b74 ("[media] V4L: Add support for integer menu controls with standard menu items")
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> ---
>  drivers/media/v4l2-core/v4l2-ctrls-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> index 1f85828d6694..322f9f715b65 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> @@ -1762,7 +1762,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
>  	else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
>  		qmenu_int = v4l2_ctrl_get_int_menu(id, &qmenu_int_len);
>  
> -	if ((!qmenu && !qmenu_int) || (qmenu_int && max > qmenu_int_len)) {
> +	if ((!qmenu && !qmenu_int) || (qmenu_int && max >= qmenu_int_len)) {
>  		handler_set_err(hdl, -EINVAL);
>  		return NULL;
>  	}

Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

-- 
Kind regards,

Sakari Ailus

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

end of thread, other threads:[~2022-09-26 17:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 16:31 [PATCH] media: v4l2-ctrls: Fix off-by-one error in integer menu control check Laurent Pinchart
2022-09-26 16:40 ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).