Skip to contentSkip to conversation

virtio-net: use g_memdup2() instead of unsafe g_memdup()

PATCH In review Eugenio Pérez 3 participants 4 messages Mar 31, 2022 – Apr 1, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-net: use g_memdup2() instead of unsafe g_memdup()

Fixing that literal checkpatch.pl because it will complain when we modify the file

---
 hw/net/virtio-net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +2 -1
index 1067e72b39..e4748a7e6c 100644
@@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         }
 
         iov_cnt = elem->out_num;
-        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
+        iov2 = iov = g_memdup2(elem->out_sg,
+                               sizeof(struct iovec) * elem->out_num);
         s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
         iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
         if (s != sizeof(ctrl)) {

--
2.27.0

Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Eugenio Pérez

Fixing that literal checkpatch.pl because it will complain when we modify the file

Quoted 21 lines
---
 hw/net/virtio-net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +2 -2
index 1067e72b39..e4748a7e6c 100644
@@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
         }
 
         iov_cnt = elem->out_num;
-        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
+        iov2 = iov = g_memdup2(elem->out_sg,
+                               sizeof(struct iovec) * elem->out_num);
         s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
         iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
         if (s != sizeof(ctrl)) {
--

2.27.0

#2 lore raw
Quoted 3 lines · Jason Wang
Quoted 2 lines · Eugenio Pérez

Fixing that literal checkpatch.pl because it will complain when we modify the file

See https://www.mail-archive.com/[email protected]/msg834178.html

Quoted 26 lines
Quoted 1 line
Quoted 21 lines
---
  hw/net/virtio-net.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +2 -2
index 1067e72b39..e4748a7e6c 100644
@@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
          }
 
          iov_cnt = elem->out_num;
-        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
+        iov2 = iov = g_memdup2(elem->out_sg,
+                               sizeof(struct iovec) * elem->out_num);
          s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
          iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
          if (s != sizeof(ctrl)) {
--

2.27.0

#3 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Jason Wang
Quoted 2 lines · Eugenio Pérez

Fixing that literal checkpatch.pl because it will complain when we modify the file

See https://www.mail-archive.com/[email protected]/msg834178.html

Sorry I missed that series. It performs more replacements so regarding virtio it's better to push yours.

Thanks!

Quoted 27 lines
Quoted 26 lines
Quoted 1 line
Quoted 21 lines
---
  hw/net/virtio-net.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +2 -2
index 1067e72b39..e4748a7e6c 100644
@@ -1443,7 +1443,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
          }
 
          iov_cnt = elem->out_num;
-        iov2 = iov = g_memdup(elem->out_sg, sizeof(struct iovec) * elem->out_num);
+        iov2 = iov = g_memdup2(elem->out_sg,
+                               sizeof(struct iovec) * elem->out_num);
          s = iov_to_buf(iov, iov_cnt, 0, &ctrl, sizeof(ctrl));
          iov_discard_front(&iov, &iov_cnt, sizeof(ctrl));
          if (s != sizeof(ctrl)) {
--

2.27.0