gspca: add missing .type field check in VIDIOC_G_PARM

Message ID 49C2C3C8.3000300@freemail.hu (mailing list archive)
State Superseded, archived
Headers

Commit Message

Németh Márton March 19, 2009, 10:14 p.m. UTC
  From: Márton Németh <nm127@freemail.hu>

The gspca webcam driver does not check the .type field of struct v4l2_streamparm.
This field is an input parameter for the driver according to V4L2 API specification,
revision 0.24 [1]. Add the missing check.

The missing check was recognised by v4l-test 0.10 [2] together with gspca_sunplus driver
and with "Trust 610 LCD POWERC@M ZOOM" webcam. This patch was verified also with
v4l-test 0.10.

The memset() is not necessary as V4L2 framework already have done this task when
vidioc_g_parm() is called.

References:
[1] V4L2 API specification, revision 0.24
    http://v4l2spec.bytesex.org/spec/r11680.htm

[2] v4l-test: Test environment for Video For Linux Two API
    http://v4l-test.sourceforge.net/

Signed-off-by: Márton Németh <nm127@freemail.hu>
---
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Comments

Trent Piepho March 20, 2009, 12:47 a.m. UTC | #1
On Thu, 19 Mar 2009, [UTF-8] Németh Márton wrote:
> The gspca webcam driver does not check the .type field of struct v4l2_streamparm.
> This field is an input parameter for the driver according to V4L2 API specification,
> revision 0.24 [1]. Add the missing check.

I think this check could go in the v4l2 core too.  It already does a
similar check for QUERYBUF, QBUF, DQBUF, etc.  If the driver doesn't
provide a method for ->vidioc_try_fmt_foo() then the v4l2 core will reject
a call with .type == V4L2_BUF_TYPE_foo.

It seems like it should be ok to do this for S_PARM and G_PARM too.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  
Mauro Carvalho Chehab March 27, 2009, 10:42 a.m. UTC | #2
On Thu, 19 Mar 2009 17:47:13 -0700 (PDT)
Trent Piepho <xyzzy@speakeasy.org> wrote:

> On Thu, 19 Mar 2009, [UTF-8] Németh Márton wrote:
> > The gspca webcam driver does not check the .type field of struct v4l2_streamparm.
> > This field is an input parameter for the driver according to V4L2 API specification,
> > revision 0.24 [1]. Add the missing check.
> 
> I think this check could go in the v4l2 core too.  It already does a
> similar check for QUERYBUF, QBUF, DQBUF, etc.  If the driver doesn't
> provide a method for ->vidioc_try_fmt_foo() then the v4l2 core will reject
> a call with .type == V4L2_BUF_TYPE_foo.
> 
> It seems like it should be ok to do this for S_PARM and G_PARM too.

I agree. Could you provide such patch?

Cheers,
Mauro
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  

Patch

--- linux-2.6.29-rc8/drivers/media/video/gspca/gspca.c.orig	2009-03-14 12:29:38.000000000 +0100
+++ linux-2.6.29-rc8/drivers/media/video/gspca/gspca.c	2009-03-19 20:38:22.000000000 +0100
@@ -1320,8 +1320,9 @@  static int vidioc_g_parm(struct file *fi
 {
 	struct gspca_dev *gspca_dev = priv;

-	memset(parm, 0, sizeof *parm);
-	parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+		return -EINVAL;
+
 	parm->parm.capture.readbuffers = gspca_dev->nbufread;

 	if (gspca_dev->sd_desc->get_streamparm) {