i2c: Add a length check to the SMBus write handling
PATCH 1/1 i2c: Add a length check to the SMBus write handling
From: Corey Minyard <[email protected]>
Avoid an overflow.
Signed-off-by Corey Minyard <[email protected]>
Reviewed-by Peter Maydell <[email protected]>
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Cc QEMU Stable <[email protected]>
--- hw/i2c/smbus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/smbus.c +5 -1
@@ -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);
Signature · 1 line
2.17.1
Peter Maydell
AppliedQuoted 10 lines · On Mon, 3 Dec 2018 at 12:53, <[email protected]> wrote:
From: Corey Minyard <[email protected]>
Avoid an overflow.
Signed-off-by Corey Minyard <[email protected]>Reviewed-by Peter Maydell <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Cc QEMU Stable <[email protected]>
Applied to master for rc4, thanks.
-- PMM