From: Corey Minyard Date: Sun, 31 Jul 2022 22:58:09 +0000 (-0500) Subject: ipmi:smbus: Add a check around a memcpy X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3fde641e7286f9b968bdb3b4b922c6465f2a9abc;p=qmiga%2Fqemu.git ipmi:smbus: Add a check around a memcpy In one case: memcpy(sid->inmsg + sid->inlen, buf, len); if len == 0 then sid->inmsg + sig->inlen can point to one past the inmsg array if the array is full. We have to allow len == 0 due to some vagueness in the spec, but we don't have to call memcpy. Found by Coverity. This is not a problem in practice, but the results are technically (maybe) undefined. So make Coverity happy. Reported-by: Peter Maydell Signed-off-by: Corey Minyard Acked-by: Michael S. Tsirkin Reviewed-by: Peter Maydell --- diff --git a/hw/ipmi/smbus_ipmi.c b/hw/ipmi/smbus_ipmi.c index 9ef9112dd5..d0991ab7f9 100644 --- a/hw/ipmi/smbus_ipmi.c +++ b/hw/ipmi/smbus_ipmi.c @@ -281,7 +281,9 @@ static int ipmi_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) */ send = true; } - memcpy(sid->inmsg + sid->inlen, buf, len); + if (len > 0) { + memcpy(sid->inmsg + sid->inlen, buf, len); + } sid->inlen += len; break; }