Skip to content

Commit

Permalink
i2c: Add a length check to the SMBus write handling
Browse files Browse the repository at this point in the history
Avoid an overflow.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: QEMU Stable <qemu-stable@nongnu.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
cminyard authored and pm215 committed Dec 3, 2018
1 parent 4750e1a commit 629457a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hw/i2c/smbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 629457a

Please sign in to comment.