[PATCH 5/6] virNetDevGetEthtoolGFeatures: Avoid use of VIR_ALLOC_VAR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In this case we need a 'struct ethtool_gfeatures' followed by two
'struct ethtool_get_features_block' so there's no risk of overflow.

Use g_malloc0 and sizeof() to allocate the memory instead of
VIR_ALLOC_VAR.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virnetdev.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 1ef7cea20a..6ee59989ed 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -3300,9 +3300,8 @@ virNetDevGetEthtoolGFeatures(const char *ifname,
 {
     g_autofree struct ethtool_gfeatures *g_cmd = NULL;

-    if (VIR_ALLOC_VAR(g_cmd,
-                      struct ethtool_get_features_block, GFEATURES_SIZE) < 0)
-        return -1;
+    g_cmd = g_malloc0(sizeof(struct ethtool_gfeatures) +
+                      sizeof(struct ethtool_get_features_block) * GFEATURES_SIZE);

     g_cmd->cmd = ETHTOOL_GFEATURES;
     g_cmd->size = GFEATURES_SIZE;
-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux