[libcamera-devel,2/5] v4l2: v4l2_camera_proxy: Fix bounds check for VIDIOC_ENUM_FMT

Message ID 20200603141609.18584-3-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • Support qv4l2 with v4l2-compat
Related show

Commit Message

Paul Elder June 3, 2020, 2:16 p.m. UTC
VIDIOC_ENUM_FMT is meant to return -EINVAL if the requested index is out
of bounds. This bounds is obtained from the libcamera Camera's list of
formats. The bounds check for this list was incorrect; fix it.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/v4l2/v4l2_camera_proxy.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Laurent Pinchart June 3, 2020, 8:52 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Wed, Jun 03, 2020 at 11:16:06PM +0900, Paul Elder wrote:
> VIDIOC_ENUM_FMT is meant to return -EINVAL if the requested index is out
> of bounds. This bounds is obtained from the libcamera Camera's list of
> formats. The bounds check for this list was incorrect; fix it.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/v4l2/v4l2_camera_proxy.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
> index 3df4d42b..ec6d265d 100644
> --- a/src/v4l2/v4l2_camera_proxy.cpp
> +++ b/src/v4l2/v4l2_camera_proxy.cpp
> @@ -224,7 +224,7 @@ int V4L2CameraProxy::vidioc_enum_fmt(struct v4l2_fmtdesc *arg)
>  	LOG(V4L2Compat, Debug) << "Servicing vidioc_enum_fmt";
>  
>  	if (!validateBufferType(arg->type) ||
> -	    arg->index > streamConfig_.formats().pixelformats().size())
> +	    arg->index >= streamConfig_.formats().pixelformats().size())
>  		return -EINVAL;
>  
>  	/* \todo Add map from format to description. */

Patch

diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index 3df4d42b..ec6d265d 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -224,7 +224,7 @@  int V4L2CameraProxy::vidioc_enum_fmt(struct v4l2_fmtdesc *arg)
 	LOG(V4L2Compat, Debug) << "Servicing vidioc_enum_fmt";
 
 	if (!validateBufferType(arg->type) ||
-	    arg->index > streamConfig_.formats().pixelformats().size())
+	    arg->index >= streamConfig_.formats().pixelformats().size())
 		return -EINVAL;
 
 	/* \todo Add map from format to description. */