From nobody Sun Feb 8 22:07:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1584353611; cv=none; d=zohomail.com; s=zohoarc; b=ZnhEao7zUBPWfxcTUDBhIMu4pcbE81SfKOmtlWJXw7uzIhNhg4fIO7IwOx8xqSKDiDflxisfihBc4t3eJOmU9nPmOHYCkETbWhzkcTQHyZTt2CjayWk1vsUP4IB0L7CVhz8Am/8ukA+0iaetoXbQGqCVcgTMSVyCUNESURn1ibg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584353611; h=Content-Type:Content-Transfer-Encoding:Cc: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=8OCalDOdo7M6XA4GTkA8EyPk2MMFDwbYCA9PnVeTBM8=; b=QqFWmohNE0+ONNLzW2RounloOI1KEKtNwL2C7S9VrWE/Yp1FXXR6EMOIuCYrvx3Y/tEb7PskOVumnyx9AwN91Mt45mf8Q2h1Jey6SgpJl/1PBsEwtPeryyN7Ha/ro9/xVABir3lOe3mPV3HcTasGZedjyBcfSA5kXkfRsP71l+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1584353611711226.99557481559293; Mon, 16 Mar 2020 03:13:31 -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-304-2_WjdphoNmu8GM4erHODow-1; Mon, 16 Mar 2020 06:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F69D802B9B; Mon, 16 Mar 2020 10:13:23 +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 EDC6B60BF3; Mon, 16 Mar 2020 10:13:22 +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 2F3C7182B010; Mon, 16 Mar 2020 10:13:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02GADJ6c030221 for ; Mon, 16 Mar 2020 06:13:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8BBB93533; Mon, 16 Mar 2020 10:13:19 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFADC94965; Mon, 16 Mar 2020 10:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584353610; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=8OCalDOdo7M6XA4GTkA8EyPk2MMFDwbYCA9PnVeTBM8=; b=OcZ0E+3bwqkwLZjdhfcM1blrQfJCW6E8VJXQf1tr3qn09sTG8i6XitVTahAtRuf+GzSUFf IsLiQbNx0pPADaP59/NZ8PGRjAePYtd4g6xftTHe1bWh/0eFXGIf+Ojo1BlYs7w6Xlg6jW IGYMQ9CA4nwO8PA1fiiT3mbWFwsgKs0= X-MC-Unique: 2_WjdphoNmu8GM4erHODow-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 2/5] qemuDomainSecretAESSetup: Automatically free non-secret locals Date: Mon, 16 Mar 2020 11:13:04 +0100 Message-Id: <98ba8c3f348dcd4a5579ba9fdcedc49258f1defb.1584353498.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa 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.12 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" Use g_autofree for the ciphertext and init vector as they are not secret and thus don't have to be cleared and use g_new0 to allocate the iv for parity. Signed-off-by: Peter Krempa --- src/qemu/qemu_domain.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7c962fb062..e33d3099d6 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1536,11 +1536,11 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr pr= iv, { g_autoptr(virConnect) conn =3D virGetConnectSecret(); int ret =3D -1; - uint8_t *raw_iv =3D NULL; + g_autofree uint8_t *raw_iv =3D NULL; size_t ivlen =3D QEMU_DOMAIN_AES_IV_LEN; uint8_t *secret =3D NULL; size_t secretlen =3D 0; - uint8_t *ciphertext =3D NULL; + g_autofree uint8_t *ciphertext =3D NULL; size_t ciphertextlen =3D 0; if (!conn) @@ -1550,14 +1550,13 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr pr= iv, secinfo->s.aes.username =3D g_strdup(username); if (!(secinfo->s.aes.alias =3D qemuDomainGetSecretAESAlias(srcalias, i= sLuks))) - goto cleanup; + return -1; - if (VIR_ALLOC_N(raw_iv, ivlen) < 0) - goto cleanup; + raw_iv =3D g_new0(uint8_t, ivlen); /* Create a random initialization vector */ if (virRandomBytes(raw_iv, ivlen) < 0) - goto cleanup; + return -1; /* Encode the IV and save that since qemu will need it */ secinfo->s.aes.iv =3D g_base64_encode(raw_iv, ivlen); @@ -1583,9 +1582,7 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv, ret =3D 0; cleanup: - VIR_DISPOSE_N(raw_iv, ivlen); VIR_DISPOSE_N(secret, secretlen); - VIR_DISPOSE_N(ciphertext, ciphertextlen); return ret; } --=20 2.24.1