From nobody Fri May 3 07:14:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1506525150811274.12650459369024; Wed, 27 Sep 2017 08:12:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 16041C04D936; Wed, 27 Sep 2017 15:12:29 +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 B1E0089F01; Wed, 27 Sep 2017 15:12:26 +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 F1D513FAD2; Wed, 27 Sep 2017 15:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8REMLrT006670 for ; Wed, 27 Sep 2017 10:22:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7CE4F89205; Wed, 27 Sep 2017 14:22:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-1.phx2.redhat.com [10.3.117.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id 455458922A for ; Wed, 27 Sep 2017 14:22:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 16041C04D936 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Wed, 27 Sep 2017 10:22:17 -0400 Message-Id: <20170927142217.30717-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] nwfilter: Fix possible segfault on sometimes consumed variable 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 27 Sep 2017 15:12:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virNWFilterIPAddrMapAddIPAddr code can consume the @addr parameter on success when the @ifname is found in the ipAddressMap->hashTable hash table in the call to virNWFilterVarValueAddValue; however, if not found in the hash table, then @addr is formatted into a @val which is stored in the table and on return the caller would be expected to free @addr. Thus, the caller has no way to determine on success whether @addr was consumed, so in order to fix this create a @tmp variable which will be stored/consumed when virNWFilterVarValueAddValue succeeds. That way the caller can free @addr whether the function returns success or failure. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- src/conf/nwfilter_ipaddrmap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index 9c8584ce2..5668f366d 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -26,7 +26,9 @@ =20 #include "internal.h" =20 +#include "viralloc.h" #include "virerror.h" +#include "virstring.h" #include "datatypes.h" #include "nwfilter_params.h" #include "nwfilter_ipaddrmap.h" @@ -52,6 +54,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *a= ddr) { int ret =3D -1; virNWFilterVarValuePtr val; + char *tmp =3D NULL; =20 virMutexLock(&ipAddressMapLock); =20 @@ -65,14 +68,18 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char = *addr) virNWFilterVarValueFree(val); goto cleanup; } else { - if (virNWFilterVarValueAddValue(val, addr) < 0) + if (VIR_STRDUP(tmp, addr) < 0) goto cleanup; + if (virNWFilterVarValueAddValue(val, tmp) < 0) + goto cleanup; + tmp =3D NULL; } =20 ret =3D 0; =20 cleanup: virMutexUnlock(&ipAddressMapLock); + VIR_FREE(tmp); =20 return ret; } --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list