From nobody Mon Feb 9 10:38:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612359363; cv=none; d=zohomail.com; s=zohoarc; b=b82Yh/B4qgTU/AcOD+MIk2m9XbWwesVqunlARQtxJFD8hDwvQAEP/6vZjI1ju81Qiz+bRR72/T914OO2lHFPNANUtNY+0JyVw4SNME0Wa3uq9ntVUd/Q5RmTgL1WalMzl0o60/C5xVSYxGZ385Z8tjQLQP1yGVh+3ky8lx9mJFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359363; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f9nbjpEXs/iaNlvm1W9+m74L86ihk6k85xonA7rQ0AI=; b=maG6WfDl2Gm9C+6cYXNR3dfQ3rSAR3Ca8Qlh877z8iTUfYX23KWSGrA9nvtQKMCGq8dOXiYKfA42yYzHStyEbfud+N6i34kBPr8a2WBMsUy91jHXV9nW21CBAAFhAPqrTvNAQSMV+ybUt5nwT/T3SracZ81ri9WDFVJI5WPE+9g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612359363620721.1465712341769; Wed, 3 Feb 2021 05:36:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-ucZG3T3-NoCHlZ-VONQsBQ-1; Wed, 03 Feb 2021 08:35:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47933814318; Wed, 3 Feb 2021 13:35:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 209C162680; Wed, 3 Feb 2021 13:35:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D4F3485CD; Wed, 3 Feb 2021 13:35:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 113DYbhw014096 for ; Wed, 3 Feb 2021 08:34:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4F10D2CFCE; Wed, 3 Feb 2021 13:34:37 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6FC55C6B8 for ; Wed, 3 Feb 2021 13:34:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359362; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=f9nbjpEXs/iaNlvm1W9+m74L86ihk6k85xonA7rQ0AI=; b=BjTbUedZov3jfiuXoYBfHioX6UZlIMQgmqAMoNp1MLgDc47hfKUOppviYbSodb4cj2b0Lj nYiEu+ByAO8xIwo2frxj0BDiSvutdQPRVtZ2L0+DQtuAl9QDbaegPV3unI8lRbruj5itw6 5bYgkFWfbRUxm8a32fd51D43Adr1VNI= X-MC-Unique: ucZG3T3-NoCHlZ-VONQsBQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/6] virNetDevGetEthtoolGFeatures: Avoid use of VIR_ALLOC_VAR Date: Wed, 3 Feb 2021 14:34:25 +0100 Message-Id: <50aed380de268b8134a2479948342b3c9f95bb05.1612358891.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D NULL; - if (VIR_ALLOC_VAR(g_cmd, - struct ethtool_get_features_block, GFEATURES_SIZE) <= 0) - return -1; + g_cmd =3D g_malloc0(sizeof(struct ethtool_gfeatures) + + sizeof(struct ethtool_get_features_block) * GFEATURE= S_SIZE); g_cmd->cmd =3D ETHTOOL_GFEATURES; g_cmd->size =3D GFEATURES_SIZE; --=20 2.29.2