From nobody Sat May 18 23:55:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1673427018; cv=none; d=zohomail.com; s=zohoarc; b=PMJhEHokQpd69wc6+KAMeKsCsp6UGNub2lzfakt6w0mhy3SjwqDYVCaPE5+j+GsCdi/LSA8iOW7C5yqp0LN2dU+tb9jc2aOr8CfMC5jUdGvfDQE37jwDXT2gl4qxkgAOTC4N5uuAI72KYbywgJuREowoaaaw2RO4OPDa0BDz5S8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673427018; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Ytix5dNtuRtetTaNBJYRxP74oDFBV59TS7JWIFc80RM=; b=cnPvmmIUK2aenBFED3PtdXH7AUF4TKmeGuNNgRIILoMwsKDFw1PnqW/QL5HhmxcVX12CX8c9J90rGV6xC1IIt2Hu95BcZCMrvEIxmCtFJi42a3tH8BZoX7UFMnCS+oO4qrr2U401vH/usLCCy+q8NuPfUWqr7pH9MYkhShCet/w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1673427018547402.8771523593339; Wed, 11 Jan 2023 00:50:18 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-13-YeWSpRubM5-I3pHdZaSMAw-1; Wed, 11 Jan 2023 03:50:12 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC68B80D0E7; Wed, 11 Jan 2023 08:50:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A935CC16031; Wed, 11 Jan 2023 08:50:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 799941946589; Wed, 11 Jan 2023 08:50:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 617E91946587 for ; Wed, 11 Jan 2023 08:50:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1FC702026D76; Wed, 11 Jan 2023 08:50:07 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id D661C2026D68 for ; Wed, 11 Jan 2023 08:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673427017; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ytix5dNtuRtetTaNBJYRxP74oDFBV59TS7JWIFc80RM=; b=Sx6gfDLpuR36y1NyIViQUmbJ1lHstahs75AoOmFZXym/r58uESqUKvaVqcte4t/rt0BojD uo2ApR+dBNL6Q404VsaJ1oeyCDcpo/dVRX842gK0MPvuNV9SjQTyKSCJutM8/N6BF5cIXr woYUgcMSREKIeNVNEU5qEY7NQKEiAdc= X-MC-Unique: YeWSpRubM5-I3pHdZaSMAw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH] conf: Avoid NULL dereference in virDomainNetPortForwardFree Date: Wed, 11 Jan 2023 09:49:51 +0100 Message-Id: <9615791925e3108ecb7bedfd8a1fa11164e517af.1673426991.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673427018909100001 Content-Type: text/plain; charset="utf-8" In our current code the function is not called with NULL argument, but we should follow our common practice and make it safe anyway. Reported by coverity: /src/conf/domain_conf.c: 2635 in virDomainNetPortForwardFree() 2629 { 2630 size_t i; 2631 2632 if (pf) 2633 g_free(pf->dev); 2634 >>> CID 404359: Null pointer dereferences (FORWARD_NULL) >>> Dereferencing null pointer "pf". 2635 for (i =3D 0; i < pf->nRanges; i++) 2636 g_free(pf->ranges[i]); 2637 2638 g_free(pf->ranges); 2639 g_free(pf); 2640 } Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina --- src/conf/domain_conf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 598e23b005..e43dee1a60 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2629,8 +2629,10 @@ virDomainNetPortForwardFree(virDomainNetPortForward = *pf) { size_t i; =20 - if (pf) - g_free(pf->dev); + if (!pf) + return; + + g_free(pf->dev); =20 for (i =3D 0; i < pf->nRanges; i++) g_free(pf->ranges[i]); --=20 2.39.0