From nobody Mon Nov 25 23:25:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1592309258; cv=none; d=zohomail.com; s=zohoarc; b=esjE6521lZ8GmIzv+AGWBBr2RGP5gcS+357nLyM8+0p+vIiF5XHbsX1nZ7Vugoh5u7qlUOqS4hlCv3DPhlQLLSczmYOD3t91Pnkt/exy0i9Kbwa+FLyivsaQj4ctxY0g/CirhMDJLYlHwZ7rwl4J7NpF7/qbafgcvqW14Y4bZF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592309258; 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=CxdkP9wglXnxBcnI0TQJOnYxtutIMAReyhLaJsO41YM=; b=AJZxTQbIHD83hYvoOk+lsnm1hdanH1R263sOFdDI/11I2r+hGX5UYzqLEGP8RFrohJZ3SaFA5EO2GPEV7p4b1o+SU4QAzha/UcGkJR/J+iQfW63JDvuLeosJBu+E61AkbwNB/jdVTK8sTtgCWNL0XCMvmSaFSC/NpTxg35iMY2c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1592309258984816.307269472468; Tue, 16 Jun 2020 05:07:38 -0700 (PDT) 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-159-X5skAjQyPQyHOwPlMav16A-1; Tue, 16 Jun 2020 08:07:35 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D539E91C; Tue, 16 Jun 2020 12:07:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3CB021001B07; Tue, 16 Jun 2020 12:07:27 +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 EE3CB1809563; Tue, 16 Jun 2020 12:07:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05GC7GXi001095 for ; Tue, 16 Jun 2020 08:07:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3EAFB5D9DA; Tue, 16 Jun 2020 12:07:16 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.com (ovpn-112-147.phx2.redhat.com [10.3.112.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3A2B5D9D5 for ; Tue, 16 Jun 2020 12:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592309257; 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=CxdkP9wglXnxBcnI0TQJOnYxtutIMAReyhLaJsO41YM=; b=fV7j5s3uqjC0ch4d3GpA3XL02+0gqAMRQ0a3OBIoz5DttRfOishodTR+5/1NBD6qzfzqFp rb1TUOGr90+e64gRH404DrrT7m3NvCYLgSGcOo0bnXIiS3fhpTDuw6mCHhD3CWny19dhcB 1B3laaV2xC0g3snWBkl9WhzlzzEZeBs= X-MC-Unique: X5skAjQyPQyHOwPlMav16A-1 From: John Ferlan To: libvir-list@redhat.com Subject: [PATCH 1/9] util: Fix memory leak in virAuthGetCredential Date: Tue, 16 Jun 2020 08:07:02 -0400 Message-Id: <20200616120710.2628344-2-jferlan@redhat.com> In-Reply-To: <20200616120710.2628344-1-jferlan@redhat.com> References: <20200616120710.2628344-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.84 on 10.5.11.22 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" Since 5084091a, @tmp is filled by a g_key_file_get_string which is now an allocated string as opposed to some hash table lookup value, so we need to treat it as so. Found by Coverity Signed-off-by: John Ferlan --- src/remote/remote_driver.c | 2 +- src/util/virauth.c | 5 +---- src/util/virauthconfig.c | 2 +- src/util/virauthconfig.h | 2 +- tests/virauthconfigtest.c | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 0aeab9db27..653c68472a 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -4097,7 +4097,7 @@ static int remoteAuthFillFromConfig(virConnectPtr con= n, } =20 for (ninteract =3D 0; state->interact[ninteract].id !=3D 0; ninteract+= +) { - const char *value =3D NULL; + char *value =3D NULL; =20 switch (state->interact[ninteract].id) { case SASL_CB_USER: diff --git a/src/util/virauth.c b/src/util/virauth.c index f75e674586..105fca16eb 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -107,7 +107,6 @@ virAuthGetCredential(const char *servicename, char **value) { g_autoptr(virAuthConfig) config =3D NULL; - const char *tmp; =20 *value =3D NULL; =20 @@ -121,11 +120,9 @@ virAuthGetCredential(const char *servicename, servicename, hostname, credname, - &tmp) < 0) + value) < 0) return -1; =20 - *value =3D g_strdup(tmp); - return 0; } =20 diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 1c007757c7..8289b28d34 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -99,7 +99,7 @@ int virAuthConfigLookup(virAuthConfigPtr auth, const char *service, const char *hostname, const char *credname, - const char **value) + char **value) { g_autofree char *authgroup =3D NULL; g_autofree char *credgroup =3D NULL; diff --git a/src/util/virauthconfig.h b/src/util/virauthconfig.h index de28b1ff28..b6f5b5c110 100644 --- a/src/util/virauthconfig.h +++ b/src/util/virauthconfig.h @@ -37,6 +37,6 @@ int virAuthConfigLookup(virAuthConfigPtr auth, const char *service, const char *hostname, const char *credname, - const char **value); + char **value); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virAuthConfig, virAuthConfigFree); diff --git a/tests/virauthconfigtest.c b/tests/virauthconfigtest.c index 20855f004e..a88b453543 100644 --- a/tests/virauthconfigtest.c +++ b/tests/virauthconfigtest.c @@ -42,7 +42,7 @@ struct ConfigLookupData { static int testAuthLookup(const void *args) { const struct ConfigLookupData *data =3D args; - const char *actual =3D NULL; + g_autofree char *actual =3D NULL; int rv; =20 rv =3D virAuthConfigLookup(data->config, --=20 2.25.4