gspca: add missing .type field check in VIDIOC_G_PARM
PATCH 1/1 gspca: add missing .type field check in VIDIOC_G_PARM
From: Márton Németh <[email protected]>
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.
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/
---
drivers/media/video/gspca/gspca.c renamed from drivers/media/video/gspca/gspca.c.orig +3 -0
@@ -1320,6 +1320,9 @@ static int vidioc_g_parm(struct file *fi {struct gspca_dev *gspca_dev = priv; +if (parm->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE ) +return -EINVAL ; +memset (parm,0 ,sizeof *parm); parm->type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; parm->parm.capture.readbuffers = gspca_dev->nbufread;
2009/3/18 Németh Márton <[email protected]>:
Quoted 22 lines
From: Márton Németh <[email protected]>
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_sunplusdriver and with "Trust 610 LCD POWERC@M ZOOM" webcam. This patch was verified also with v4l-test 0.10.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 <[email protected]>---
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 static int vidioc_g_parm(struct file *fi · line 1327
Quoted 8 lines
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 renamed from drivers/media/video/gspca/gspca.c.orig 2009-03-14 12:29:38.000000000 +0100 +3
-0@@ -1320,6 +1320,9 @@ static int vidioc_g_parm(struct file *fi { struct gspca_dev *gspca_dev = priv; + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + memset(parm, 0, sizeof *parm); parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
^^^^^^^^^^^^^^^^^^^
This line should be deleted as it's no longer needed.
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 static int vidioc_g_parm(struct file *fi · line 1328
Quoted 2 lines
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 renamed from drivers/media/video/gspca/gspca.c.orig 2009-03-14 12:29:38.000000000 +0100 +0
-0parm->parm.capture.readbuffers = gspca_dev->nbufread;
Regards,
David Ellingsworth
Quoted 26 lines · David Ellingsworth
2009/3/18 Németh Márton <[email protected]>:
Quoted 25 lines
From: Márton Németh <[email protected]>
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_sunplusdriver and with "Trust 610 LCD POWERC@M ZOOM" webcam. This patch was verified also with v4l-test 0.10.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 <[email protected]>---
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 renamed from drivers/media/video/gspca/gspca.c.orig 2009-03-14 12:29:38.000000000 +0100 +0
-0@@ -1320,6 +1320,9 @@ static int vidioc_g_parm(struct file *fi { struct gspca_dev *gspca_dev = priv;
Quoted 7 lines
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 static int vidioc_g_parm(struct file *fi · line 1327
Quoted 5 lines
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 renamed from drivers/media/video/gspca/gspca.c.orig 2009-03-14 12:29:38.000000000 +0100 +3
-0+ if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + memset(parm, 0, sizeof *parm); parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;^^^^^^^^^^^^^^^^^^^
This line should be deleted as it's no longer needed.
Because memset() clears the whole parm structure this line is necessary. In other drivers the following code is there:
tmp = parm->type;
memset(parm, 0, sizeof(*parm));
parm->type = parm;Maybe changing the code similar to this would be easier to read?
Márton Németh
Németh Márton wrote:
From: Márton Németh <[email protected]>
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.
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/
---
drivers/media/video/gspca/gspca.c renamed from drivers/media/video/gspca/gspca.c.orig +6 -1
@@ -1319,9 +1319,14 @@ static int vidioc_g_parm(struct file *fi struct v4l2_streamparm *parm) {struct gspca_dev *gspca_dev = priv; +enum v4l2_buf_type type; +if (parm->type !=V4L2_BUF_TYPE_VIDEO_CAPTURE ) +return -EINVAL ; + + type = parm->type;memset (parm,0 ,sizeof *parm); - parm->type =V4L2_BUF_TYPE_VIDEO_CAPTURE ; + parm->type = type; parm->parm.capture.readbuffers = gspca_dev->nbufread;if (gspca_dev->sd_desc->get_streamparm) {
Quoted 35 lines · On Thu, 19 Mar 2009, [ISO-8859-1] N�meth M�rton wrote:
Quoted 26 lines · David Ellingsworth
2009/3/18 N�meth M�rton <[email protected]>:
Quoted 25 lines
From: M�rton N�meth <[email protected]>
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_sunplusdriver and with "Trust 610 LCD POWERC@M ZOOM" webcam. This patch was verified also with v4l-test 0.10.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 <[email protected]>---
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 renamed from drivers/media/video/gspca/gspca.c.orig 2009-03-14 12:29:38.000000000 +0100 +0
-0@@ -1320,6 +1320,9 @@ static int vidioc_g_parm(struct file *fi { struct gspca_dev *gspca_dev = priv;Quoted 7 lines
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 static int vidioc_g_parm(struct file *fi · line 1327
Quoted 5 lines
drivers/media/video/gspca/gspca.c 2009-03-18 16:51:03.000000000 +0100 renamed from drivers/media/video/gspca/gspca.c.orig 2009-03-14 12:29:38.000000000 +0100 +3
-0+ if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + memset(parm, 0, sizeof *parm); parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;^^^^^^^^^^^^^^^^^^^
This line should be deleted as it's no longer needed.
Quoted 6 lines
Because
memset()clears the whole parm structure this line is necessary. In other drivers the following code is there:tmp = parm->type; memset(parm, 0, sizeof(*parm)); parm->type = parm;
The memset isn't needed anymore either, I put it into v4l2_ioctl. I removed most of the code like that but I may have missed some drivers.
From: Márton Németh <[email protected]>
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/
---
drivers/media/video/gspca/gspca.c renamed from drivers/media/video/gspca/gspca.c.orig +3 -2
@@ -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) {
Quoted 3 lines · 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.
Quoted 11 lines · On Thu, 19 Mar 2009 17:47:13 -0700 (PDT) Trent Piepho <[email protected]>…
Quoted 3 lines · 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_PARMandG_PARMtoo.
I agree. Could you provide such patch?
Cheers,
Mauro