Return-Path: Received: from mail-by2nam01on0115.outbound.protection.outlook.com ([104.47.34.115]:14144 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932512AbeCCWao (ORCPT ); Sat, 3 Mar 2018 17:30:44 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Dan Carpenter , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 63/84] media: cpia2: Fix a couple off by one bugs Date: Sat, 3 Mar 2018 22:26:37 +0000 Message-ID: <20180303222518.26271-63-alexander.levin@microsoft.com> References: <20180303222518.26271-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222518.26271-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Dan Carpenter [ Upstream commit d5ac225c7d64c9c3ef821239edc035634e594ec9 ] The cam->buffers[] array has cam->num_frames elements so the > needs to be changed to >=3D 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 Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/cpia2/cpia2_v4l.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/= cpia2_v4l.c index 3dedd83f0b19..a1c59f19cf2d 100644 --- a/drivers/media/usb/cpia2/cpia2_v4l.c +++ b/drivers/media/usb/cpia2/cpia2_v4l.c @@ -808,7 +808,7 @@ static int cpia2_querybuf(struct file *file, void *fh, = struct v4l2_buffer *buf) struct camera_data *cam =3D video_drvdata(file); =20 if(buf->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE || - buf->index > cam->num_frames) + buf->index >=3D cam->num_frames) return -EINVAL; =20 buf->m.offset =3D cam->buffers[buf->index].data - cam->frame_buffer; @@ -859,7 +859,7 @@ static int cpia2_qbuf(struct file *file, void *fh, stru= ct v4l2_buffer *buf) =20 if(buf->type !=3D V4L2_BUF_TYPE_VIDEO_CAPTURE || buf->memory !=3D V4L2_MEMORY_MMAP || - buf->index > cam->num_frames) + buf->index >=3D cam->num_frames) return -EINVAL; =20 DBG("QBUF #%d\n", buf->index); --=20 2.14.1