Skip to contentSkip to conversation

hw/rdma/vmw/pvrdma_dev_ring: Replace strncpy with pstrcpy

PATCH In review Julia Suvorova 3 participants 4 messages Mar 18, 2020 – Mar 20, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/rdma/vmw/pvrdma_dev_ring: Replace strncpy with pstrcpy

ring->name is defined as 'char name[MAX_RING_NAME_SZ]'. Replace untruncated strncpy with QEMU function.
This case prevented QEMU from compiling with --enable-sanitizers.

---
 hw/rdma/vmw/pvrdma_dev_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/rdma/vmw/pvrdma_dev_ring.c +2 -2
index d7bc7f5ccc..c2b3dd70a9 100644
@@ -16,6 +16,7 @@
 #include "qemu/osdep.h"
 #include "hw/pci/pci.h"
 #include "cpu.h"
+#include "qemu/cutils.h"
 
 #include "trace.h"
 
@@ -30,8 +31,7 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev,
     int i;
     int rc = 0;
 
-    strncpy(ring->name, name, MAX_RING_NAME_SZ);
-    ring->name[MAX_RING_NAME_SZ - 1] = 0;
+    pstrcpy(ring->name, MAX_RING_NAME_SZ, name);
     ring->dev = dev;
     ring->ring_state = ring_state;
     ring->max_elems = max_elems;
Signature · 1 line
2.24.1
#1 lore raw

Thanks,
Reviewed-by: Yuval Shaia <yuval.shaia.ml.gmail.com>

Quoted 36 lines · Julia Suvorova

ring->name is defined as 'char name[MAX_RING_NAME_SZ]'. Replace untruncated strncpy with QEMU function.
This case prevented QEMU from compiling with --enable-sanitizers.

---
 hw/rdma/vmw/pvrdma_dev_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/rdma/vmw/pvrdma_dev_ring.c +2 -2
index d7bc7f5ccc..c2b3dd70a9 100644
@@ -16,6 +16,7 @@
 #include "qemu/osdep.h"
 #include "hw/pci/pci.h"
 #include "cpu.h"
+#include "qemu/cutils.h"
 
 #include "trace.h"
 
@@ -30,8 +31,7 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name,
 PCIDevice *dev,
     int i;
     int rc = 0;
 
-    strncpy(ring->name, name, MAX_RING_NAME_SZ);
-    ring->name[MAX_RING_NAME_SZ - 1] = 0;
+    pstrcpy(ring->name, MAX_RING_NAME_SZ, name);
     ring->dev = dev;
     ring->ring_state = ring_state;
     ring->max_elems = max_elems;

--
2.24.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Julia Suvorova
Quoted 8 lines · Julia Suvorova

ring->name is defined as 'char name[MAX_RING_NAME_SZ]'. Replace untruncated strncpy with QEMU function.
This case prevented QEMU from compiling with --enable-sanitizers.

---
 hw/rdma/vmw/pvrdma_dev_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Here is my equivalent patch <[email protected]> but feel free to merge this.

#3 lore raw
Quoted 6 lines · Stefan Hajnoczi
Quoted 4 lines · Julia Suvorova

ring->name is defined as 'char name[MAX_RING_NAME_SZ]'. Replace untruncated strncpy with QEMU function.
This case prevented QEMU from compiling with --enable-sanitizers.

Quoted 8 lines
Quoted 4 lines
---
 hw/rdma/vmw/pvrdma_dev_ring.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Here is my equivalent patch <[email protected]> but feel free to merge this.

Oops, sorry, I guess I didn't search carefully enough for the solution.

Quoted 1 line