Skip to contentSkip to conversation

staging: dgnc: off by one in dgnc_mgmt_ioctl()

PATCH New Dan Carpenter 1 participant 1 message Mar 10, 2015

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

PATCH 1/1 staging: dgnc: off by one in dgnc_mgmt_ioctl()

"dgnc_NumBoards" is the number of initialized elements in the dgnc_Board[] array so the comparison should be ">=" instead of ">" so we don't read invalid data. We can remove the special handling of the empty array now that we've fixed this bug.

drivers/staging/dgnc/dgnc_mgmt.c +1 -2
index 5544a8e..b89bd59 100644
@@ -153,8 +153,7 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		if (copy_from_user(&brd, uarg, sizeof(int)))
 			return -EFAULT;
 
-		if ((brd < 0) || (brd > dgnc_NumBoards) ||
-		    (dgnc_NumBoards = 0))
+		if (brd < 0 || brd >= dgnc_NumBoards)
 			return -ENODEV;
 
 		memset(&di, 0, sizeof(di));