Skip to contentSkip to conversation

spi/spidev: handle integer wrap in spidev_message()

PATCH New Dan Carpenter 1 participant 1 message Oct 18, 2011

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

PATCH 1/1 spi/spidev: handle integer wrap in spidev_message()

"k_tmp->len" and "total" are unsigned integers. The first message could be close to "bufsiz" (4096) and then the next message could be 4GB which would cause an integer overflow.

---
I have not tested this.

drivers/spi/spidev.c +1 -1
index 830adbe..aab05e1 100644
@@ -241,7 +241,7 @@ static int spidev_message(struct spidev_data *spidev,
 		k_tmp->len = u_tmp->len;
 
 		total += k_tmp->len;
-		if (total > bufsiz) {
+		if (total > bufsiz || total < k_tmp->len) {
 			status = -EMSGSIZE;
 			goto done;
 		}