diff mbox

[libv4l] : fix integer overflow

Message ID 20170509080752.GA19912@amd (mailing list archive)
State New, archived
Headers show

Commit Message

Pavel Machek May 9, 2017, 8:07 a.m. UTC
Fix integer overflow with EXPOSURE_ABSOLUTE. This is problem for
example with Nokia N900.

Signed-off-by: Pavel Machek <pavel@ucw.cz>
diff mbox

Patch

diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c
index e795aee..189fc06 100644
--- a/lib/libv4l2/libv4l2.c
+++ b/lib/libv4l2/libv4l2.c
@@ -1776,7 +1776,7 @@  int v4l2_set_control(int fd, int cid, int value)
 		if (qctrl.type == V4L2_CTRL_TYPE_BOOLEAN)
 			ctrl.value = value ? 1 : 0;
 		else
-			ctrl.value = (value * (qctrl.maximum - qctrl.minimum) + 32767) / 65535 +
+			ctrl.value = ((long long) value * (qctrl.maximum - qctrl.minimum) + 32767) / 65535 +
 				qctrl.minimum;
 
 		result = v4lconvert_vidioc_s_ctrl(devices[index].convert, &ctrl);
@@ -1812,7 +1812,7 @@  int v4l2_get_control(int fd, int cid)
 		if (v4l2_propagate_ioctl(index, VIDIOC_G_CTRL, &ctrl))
 			return -1;
 
-	return ((ctrl.value - qctrl.minimum) * 65535 +
+	return (((long long) ctrl.value - qctrl.minimum) * 65535 +
 			(qctrl.maximum - qctrl.minimum) / 2) /
 		(qctrl.maximum - qctrl.minimum);
 }