]> git.proxmox.com Git - mirror_qemu.git/commitdiff
i2c: Add a length check to the SMBus write handling
authorCorey Minyard <cminyard@mvista.com>
Mon, 3 Dec 2018 12:52:50 +0000 (06:52 -0600)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 3 Dec 2018 13:00:38 +0000 (13:00 +0000)
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>
hw/i2c/smbus.c

index 6ff77c582fe21a1e627e4eecae251d298b6b549d..30028bfcc23f92fad2140854bc184c755b986901 100644 (file)
@@ -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);