From nobody Sun Feb 8 19:56:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612284998; cv=none; d=zohomail.com; s=zohoarc; b=njQ7e4Y/d6NgMRPATRMvyMH1avnWJCxRNdnmf3ZnTNJUy/VmJx8XUaYl3+fbqpchYT4zywgmspSf8WchXu6s17nuuNtqUjXcfjF9Svx1IBwpcxq8gUuKyucjcmL74bUNpKyulO2/kzwx/65Egqg5135I4MR92+cLWb8l1Yxl7bY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612284998; 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=nDvBmCwhIM7K7rGLABqa7+gchn/yPOAcpkmL7NigqA8=; b=ezwqXbTuHcx2SoP6p0p48NNCsKw+Hc9LldJU6vTrC4EeJlM6lVZO2s8+218tT2Zc7Gv69uSshiX8p/OoVTZ86posGeHuz3U8Muz2oDQPu1mfnoGGhAdIEiYdblvyySxjuWkVCqieeR41hRA+bNma3dGzPi8O4/+EMoNQpEYJbE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612284998193330.3121194864891; Tue, 2 Feb 2021 08:56:38 -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-188-jx1W8Ou5P_SBliIFOBQYWQ-1; Tue, 02 Feb 2021 11:56:34 -0500 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 4008910CE782; Tue, 2 Feb 2021 16:56: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 1984A10016DB; Tue, 2 Feb 2021 16:56:29 +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 D45F450040; Tue, 2 Feb 2021 16:56:28 +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 112GuHTQ014884 for ; Tue, 2 Feb 2021 11:56:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id E73EA6E510; Tue, 2 Feb 2021 16:56:17 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4940560862 for ; Tue, 2 Feb 2021 16:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612284997; 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=nDvBmCwhIM7K7rGLABqa7+gchn/yPOAcpkmL7NigqA8=; b=R2FeelR30cTjUO1w518ldtQc/KvqXeyQR56PFttFL4l9MxmSXtLoll0S4bmKO/bK9zN3rI VK3nfhf04bHI3zzB6K+/DGRt/dMw7hUMSAzYw7ysZyOyjyFKeaG+9qXRfyS1M1etMgOUgT BBepovrn5U6qz3kQwOIBfFxLneIvVHc= X-MC-Unique: jx1W8Ou5P_SBliIFOBQYWQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 03/27] qemuDomainMasterKeyCreate: Don't use VIR_DISPOSE_N on failure Date: Tue, 2 Feb 2021 17:55:40 +0100 Message-Id: <140ebdffd46cfa13107cd263b393fd0a68ab242e.1612284661.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 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" When virRandomBytes fails we don't get any random bytes and even if we did they don't have to be treated as secret as they weren't used in any way. Add a temporary variable with automatic freeing for the secret buffer and assign it only on success. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_domain.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0c078a9388..2c34307c82 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -562,18 +562,19 @@ int qemuDomainMasterKeyCreate(virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv =3D vm->privateData; + g_autofree uint8_t *key =3D NULL; /* If we don't have the capability, then do nothing. */ if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_OBJECT_SECRET)) return 0; - priv->masterKey =3D g_new0(uint8_t, QEMU_DOMAIN_MASTER_KEY_LEN); - priv->masterKeyLen =3D QEMU_DOMAIN_MASTER_KEY_LEN; + key =3D g_new0(uint8_t, QEMU_DOMAIN_MASTER_KEY_LEN); - if (virRandomBytes(priv->masterKey, priv->masterKeyLen) < 0) { - VIR_DISPOSE_N(priv->masterKey, priv->masterKeyLen); + if (virRandomBytes(key, QEMU_DOMAIN_MASTER_KEY_LEN) < 0) return -1; - } + + priv->masterKey =3D g_steal_pointer(&key); + priv->masterKeyLen =3D QEMU_DOMAIN_MASTER_KEY_LEN; return 0; } --=20 2.29.2