ipmi:smbus: Add a check around a memcpy
PATCH 1/1 ipmi:smbus: Add a check around a memcpy
From: Corey Minyard <[email protected]>
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.
--- hw/ipmi/smbus_ipmi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
I think this should do it.
hw/ipmi/smbus_ipmi.c +3 -1
@@ -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 ; }
Signature · 1 line
2.25.1
Quoted 10 lines · On Sun, Jul 31, 2022 at 06:02:46PM -0500, [email protected] wrote:
From: Corey Minyard <[email protected]>
In one case:
memcpy(sid->inmsg + sid->inlen, buf, len);if len == 0 then
sid->inmsg+sig->inlencan 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.
Quoted 5 lines
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 <[email protected]>Signed-off-by Corey Minyard <[email protected]>
Quoted 23 lines
--- hw/ipmi/smbus_ipmi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)I think this should do it.
hw/ipmi/smbus_ipmi.c +3
-1@@ -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 ; }Signature · 1 line
2.25.1
Quoted 38 lines · On Mon, 1 Aug 2022 at 00:03, <[email protected]> wrote:
From: Corey Minyard <[email protected]>
In one case:
memcpy(sid->inmsg + sid->inlen, buf, len);if len == 0 then
sid->inmsg+sig->inlencan 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 <[email protected]>Signed-off-by Corey Minyard <[email protected]>--- hw/ipmi/smbus_ipmi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)I think this should do it.
hw/ipmi/smbus_ipmi.c +3
-2@@ -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 ; } --
Quoted 1 line
2.25.1
thanks
-- PMM