]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virNetDevGetEthtoolGFeatures: Avoid use of VIR_ALLOC_VAR
authorPeter Krempa <pkrempa@redhat.com>
Wed, 3 Feb 2021 12:33:24 +0000 (13:33 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Feb 2021 15:09:25 +0000 (16:09 +0100)
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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virnetdev.c

index 1ef7cea20a8b49d203056906c29206e03ec16c6a..6ee59989ed2a0c8092839cfc8eaf6abfbc0e19eb 100644 (file)
@@ -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;