[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] i2c: Add a length check to the SMBus write handling
From: |
minyard |
Subject: |
[Qemu-devel] [PATCH] i2c: Add a length check to the SMBus write handling |
Date: |
Mon, 3 Dec 2018 06:52:50 -0600 |
From: Corey Minyard <address@hidden>
Avoid an overflow.
Signed-off-by: Corey Minyard <address@hidden>
Reviewed-by: Peter Maydell <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Tested-by: Philippe Mathieu-Daudé <address@hidden>
Cc: QEMU Stable <address@hidden>
---
hw/i2c/smbus.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c
index 6ff77c582f..30028bfcc2 100644
--- a/hw/i2c/smbus.c
+++ b/hw/i2c/smbus.c
@@ -193,7 +193,11 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data)
switch (dev->mode) {
case SMBUS_WRITE_DATA:
DPRINTF("Write data %02x\n", data);
- dev->data_buf[dev->data_len++] = data;
+ if (dev->data_len >= sizeof(dev->data_buf)) {
+ BADF("Too many bytes sent\n");
+ } else {
+ dev->data_buf[dev->data_len++] = data;
+ }
break;
default:
BADF("Unexpected write in state %d\n", dev->mode);
--
2.17.1
- [Qemu-devel] [PATCH] i2c: Add a length check to the SMBus write handling,
minyard <=