OSDN Git Service

media: cpia2: Fix a couple off by one bugs
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 9 Nov 2017 21:28:14 +0000 (16:28 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Mar 2018 08:17:57 +0000 (09:17 +0100)
[ Upstream commit d5ac225c7d64c9c3ef821239edc035634e594ec9 ]

The cam->buffers[] array has cam->num_frames elements so the > needs to
be changed to >= to avoid going beyond the end of the array.  The
->buffers[] array is allocated in cpia2_allocate_buffers() if you want
to confirm.

Fixes: ab33d5071de7 ("V4L/DVB (3376): Add cpia2 camera support")

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/usb/cpia2/cpia2_v4l.c

index 9caea83..d793c63 100644 (file)
@@ -812,7 +812,7 @@ static int cpia2_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
        struct camera_data *cam = video_drvdata(file);
 
        if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
-          buf->index > cam->num_frames)
+          buf->index >= cam->num_frames)
                return -EINVAL;
 
        buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer;
@@ -863,7 +863,7 @@ static int cpia2_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
 
        if(buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
           buf->memory != V4L2_MEMORY_MMAP ||
-          buf->index > cam->num_frames)
+          buf->index >= cam->num_frames)
                return -EINVAL;
 
        DBG("QBUF #%d\n", buf->index);