Skip to content

Commit c20bc55

Browse files
committed
Input: turbografx - fix potential out of bound access
Patch 17dd3f0: "[PATCH] drivers/input/joystick: convert to dynamic input_dev allocation" from Sep 15, 2005, leads to the following static checker warning: drivers/input/joystick/turbografx.c:235 tgfx_probe() error: buffer overflow 'tgfx_buttons' 5 <= 5 drivers/input/joystick/turbografx.c 195 for (i = 0; i < n_devs; i++) { 196 if (n_buttons[i] < 1) 197 continue; 198 199 if (n_buttons[i] > 6) { ^^^^^^^^^^^^^^^^ Possibly off by one. >= 6. Let's change the upper value to ARRAY_SIZE(tgfx_buttons) to ensure we do not reach past the end of the array. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 3213afb commit c20bc55

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/input/joystick/turbografx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
196196
if (n_buttons[i] < 1)
197197
continue;
198198

199-
if (n_buttons[i] > 6) {
199+
if (n_buttons[i] > ARRAY_SIZE(tgfx_buttons)) {
200200
printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
201201
err = -EINVAL;
202202
goto err_unreg_devs;

0 commit comments

Comments
 (0)