Skip to contentSkip to conversation

ipmi:smbus: Add a check around a memcpy

PATCH In review [email protected] 3 participants 3 messages Jul 31, 2022 – Aug 1, 2022

lore
Share & tools
lore
#0 lore raw

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
index 9ef9112dd5..d0991ab7f9 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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->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.

Quoted 5 lines

Found by Coverity. This is not a problem in practice, but the results are technically (maybe) undefined. So make Coverity happy.

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
index 9ef9112dd5..d0991ab7f9 100644
@@ -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
Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
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->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 -2
index 9ef9112dd5..d0991ab7f9 100644
@@ -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