Skip to contentSkip to conversation

gspca: underflow in vidioc_s_parm()

PATCH In review Dan Carpenter 2 participants 2 messages Jan 7, 2015 – Jan 15, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gspca: underflow in vidioc_s_parm()

"n" is a user controlled integer. The code here doesn't handle the case where "n" is negative and this causes a static checker warning.

	drivers/media/usb/gspca/gspca.c:1571 vidioc_s_parm()
	warn: no lower bound on 'n'

---
I haven't followed through to see if this is a real problem.

drivers/media/usb/gspca/gspca.c +2 -0
index 43d6505..27f7da1 100644
@@ -1565,6 +1565,8 @@ static int vidioc_s_parm(struct file *filp, void *priv,
 	int n;
 
 	n = parm->parm.capture.readbuffers;
+	if (n < 0)
+		return -EINVAL;
 	if (n = 0 || n >= GSPCA_MAX_FRAMES)
 		parm->parm.capture.readbuffers = gspca_dev->nbufread;
 	else
#1 lore raw

Hi,

Quoted 9 lines · Dan Carpenter

"n" is a user controlled integer. The code here doesn't handle the case where "n" is negative and this causes a static checker warning.

	drivers/media/usb/gspca/gspca.c:1571 vidioc_s_parm()
	warn: no lower bound on 'n'

---
I haven't followed through to see if this is a real problem.

Thanks for the report, it is a real problem, but since parm->parm.capture.readbuffers is unsigned I've chosen to fix it by making n unsigned too instead.

Regards,

Hans

Quoted 15 lines
drivers/media/usb/gspca/gspca.c +2 -0
index 43d6505..27f7da1 100644
@@ -1565,6 +1565,8 @@ static int vidioc_s_parm(struct file *filp, void *priv,
  	int n;
 
  	n = parm->parm.capture.readbuffers;
+	if (n < 0)
+		return -EINVAL;
  	if (n = 0 || n >= GSPCA_MAX_FRAMES)
  		parm->parm.capture.readbuffers = gspca_dev->nbufread;
  	else