From nobody Sun May 19 08:26:00 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=1675180970; cv=none; d=zohomail.com; s=zohoarc; b=n6BR23h5CZ8L3n2d7YKKGY/7fzFFHHpVWTKbqmiTrSEU3rVGWeyqE/WlN/lR6rnpR0ffOf8xW7iEHAj0wAZSGUFMNhSQ1b2zpF45g3/JL79s+UklVSdPtwYRO/IPzcgGFSFcPvKHXUNHuwEiYPFQQ5UaQUxiy6Wdy9uNqE3T1Jk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675180970; 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=S4qPPi/2ACoIb2koGzg53TjH3y/03jYZsGdmumL1VHc=; b=a2BeTostYPY48fXzvfw+VyrXmcKSweCOQC0SDtAZ43JBCiDkN6v9eht+9Vm5+Z2YLt3WQsVuXZ+w5WCUYlOHInqXbN6nuZb3LAxHjhv1QMGqA4uyHTYmcjO+WLcHMZcsazYu1W1BrLvW2kvmoTLT/PkPx4OzBzTehoZ3PSbhmrM= 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 1675180970082469.21317584166; Tue, 31 Jan 2023 08:02:50 -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-275-ca8LEJl-MSyO3jU6lHZsnA-1; Tue, 31 Jan 2023 11:02:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A55C1991C53; Tue, 31 Jan 2023 16:02:32 +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 3D8821121333; Tue, 31 Jan 2023 16:02:32 +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 B5C5619465B6; Tue, 31 Jan 2023 16:02:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 14B5919465A0 for ; Tue, 31 Jan 2023 16:02:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id ED8AC40ED784; Tue, 31 Jan 2023 16:02:28 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36DE240ED76B for ; Tue, 31 Jan 2023 16:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675180969; 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=S4qPPi/2ACoIb2koGzg53TjH3y/03jYZsGdmumL1VHc=; b=Y8UyOhu7LD9TJ6GQq/7GfutpRdxqhrFL4KiaMZLufLEOvz89cbcJ+/C5r4aE8AoA/7Qf3S Fm9hgjNMV6xok1fnjYMsEp4l7hyMlyJXOwDjYXzLU1whIs2VV6vGDLlk7XiM6NJnXmnuME wEg3FpCaXG4BVuotrxg3ruQOTuW5ZUg= X-MC-Unique: ca8LEJl-MSyO3jU6lHZsnA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/7] virCryptoEncryptDataAESgnutls: Restructure control flow Date: Tue, 31 Jan 2023 17:02:13 +0100 Message-Id: <4c5b527c518f18c86c55819b9cb6b3a76ed7dc9b.1675180728.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.3 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: 1675180971336100002 Content-Type: text/plain; charset="utf-8" Prepare the buffer for encryption only after initializing the cipher, so that there's just one failure point. This allows to remove the 'error' label. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/util/vircrypto.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c index b28d3fc23d..12d051a55a 100644 --- a/src/util/vircrypto.c +++ b/src/util/vircrypto.c @@ -127,9 +127,17 @@ virCryptoEncryptDataAESgnutls(gnutls_cipher_algorithm_= t gnutls_enc_alg, gnutls_cipher_hd_t handle =3D NULL; gnutls_datum_t enc_key =3D { .data =3D enckey, .size =3D enckeylen }; gnutls_datum_t iv_buf =3D { .data =3D iv, .size =3D ivlen }; - uint8_t *ciphertext; + g_autofree uint8_t *ciphertext =3D NULL; size_t ciphertextlen; + if ((rc =3D gnutls_cipher_init(&handle, gnutls_enc_alg, + &enc_key, &iv_buf)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to initialize cipher: '%s'"), + gnutls_strerror(rc)); + return -1; + } + /* Allocate a padded buffer, copy in the data. * * NB, we must *always* have at least 1 byte of @@ -146,32 +154,20 @@ virCryptoEncryptDataAESgnutls(gnutls_cipher_algorithm= _t gnutls_enc_alg, for (i =3D datalen; i < ciphertextlen; i++) ciphertext[i] =3D ciphertextlen - datalen; - if ((rc =3D gnutls_cipher_init(&handle, gnutls_enc_alg, - &enc_key, &iv_buf)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to initialize cipher: '%s'"), - gnutls_strerror(rc)); - goto error; - } - /* Encrypt the data and free the memory for cipher operations */ rc =3D gnutls_cipher_encrypt(handle, ciphertext, ciphertextlen); gnutls_cipher_deinit(handle); if (rc < 0) { + virSecureErase(ciphertext, ciphertextlen); virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to encrypt the data: '%s'"), gnutls_strerror(rc)); - goto error; + return -1; } - *ciphertextret =3D ciphertext; + *ciphertextret =3D g_steal_pointer(&ciphertext); *ciphertextlenret =3D ciphertextlen; return 0; - - error: - virSecureErase(ciphertext, ciphertextlen); - g_free(ciphertext); - return -1; } --=20 2.39.1 From nobody Sun May 19 08:26:00 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=1675180971; cv=none; d=zohomail.com; s=zohoarc; b=BiQpL2DR66uKRR4+H0n5WWz+yYT+gKDe95QOyuvGajqtLjb7l0BtR9/IUSZWBtAJAWSiUjnNe2xcgfdGH1KMMsQ4FFdm7CW3Awh5LUYFo76ebpZ64UKMRAQjt/rY7oNmL/mJKoT50kO6V0zjiodSmBT+YPIUGf1/R/TwrMx56cY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675180971; 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=UcIfWK/Dk5crplhNUH/YLH4oUZ9V7vDKdqMAO+gT4Kg=; b=P5DcmxzdbAEZoCBjH2b5/yjAbGkKsB6WzIVqqZSto9GzX1Ih69cIsExMB9VpTbYlMNFeaNx82eiMF9Nxx6OhKTJrlj4iT55k4aFf9QpfdGvTKEkMapYtV8CqsXTmp28+UEK1LSpYSIMWB5stAd5Eu2Nmg2khJ6u9tI00qHBnffY= 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 1675180971236947.5897565220054; Tue, 31 Jan 2023 08:02:51 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-575-9zI2HU40Oc24NND898wx6w-1; Tue, 31 Jan 2023 11:02:39 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B904A2A5954F; Tue, 31 Jan 2023 16:02:31 +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 A3ED2112132C; Tue, 31 Jan 2023 16:02:31 +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 819291946589; Tue, 31 Jan 2023 16:02:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F27C91946595 for ; Tue, 31 Jan 2023 16:02:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D7B504010E36; Tue, 31 Jan 2023 16:02:29 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F9FF401531B for ; Tue, 31 Jan 2023 16:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675180970; 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=UcIfWK/Dk5crplhNUH/YLH4oUZ9V7vDKdqMAO+gT4Kg=; b=Jy1TlhHiGEYay/QjLQLYd8ngb+ZRNcaywodKSdCoLITVrvQ3tSzocjjD6VbN+uX60QFCdD 7wqAufzu28rGPVcnVViwYhv0uYYZY7EY9uVktJl6W15t+iD6q5L1+RW8+4L7B8sqYf3Euz cIGBUAKLiAw3ZtQO+V43K416VP6HPVE= X-MC-Unique: 9zI2HU40Oc24NND898wx6w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/7] virStorageBackendISCSISetAuth: Refactor cleanup Date: Tue, 31 Jan 2023 17:02:14 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.3 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: 1675180973081100005 Content-Type: text/plain; charset="utf-8" Automatically free 'conn' and remove the 'cleanup' section and 'ret' variable. 'datatypes.h' contains the declaration of the autoptr cleanup function for virConnect. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/storage/storage_backend_iscsi.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index 968a70158b..e4fa49d05f 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -26,6 +26,7 @@ #include #include +#include "datatypes.h" #include "driver.h" #include "storage_backend_iscsi.h" #include "viralloc.h" @@ -255,8 +256,8 @@ virStorageBackendISCSISetAuth(const char *portal, size_t secret_size; g_autofree char *secret_str =3D NULL; virStorageAuthDef *authdef =3D source->auth; - int ret =3D -1; - virConnectPtr conn =3D NULL; + int ret =3D 0; + g_autoptr(virConnect) conn =3D NULL; VIR_IDENTITY_AUTORESTORE virIdentity *oldident =3D NULL; if (!authdef || authdef->authType =3D=3D VIR_STORAGE_AUTH_TYPE_NONE) @@ -280,7 +281,7 @@ virStorageBackendISCSISetAuth(const char *portal, if (virSecretGetSecretString(conn, &authdef->seclookupdef, VIR_SECRET_USAGE_TYPE_ISCSI, &secret_value, &secret_size) < 0) - goto cleanup; + return -1; secret_str =3D g_new0(char, secret_size + 1); memcpy(secret_str, secret_value, secret_size); @@ -299,13 +300,9 @@ virStorageBackendISCSISetAuth(const char *portal, source->devices[0].path, "node.session.auth.password", secret_str) < 0) - goto cleanup; + ret =3D -1; - ret =3D 0; - - cleanup: virSecureErase(secret_str, secret_size); - virObjectUnref(conn); return ret; } --=20 2.39.1 From nobody Sun May 19 08:26:00 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=1675180986; cv=none; d=zohomail.com; s=zohoarc; b=Xmu4qMVXGq91pIpLeu5wZYPaN3p0WptQ+pdGZEETWQkHNqd81+9IjKHGsVEDQZh5sV3eLFtSwvSS+kUmbfl9UDHriuSIGw0qcDf5dXtavrKo30hQxWO1cV3th+mgU551Wi7KO456Sfni6iIcMSgHq1wcI8mHwKNSr5NLir7hVwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675180986; 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=Pz7py1yRnd9M8sizrsvQDuDDajPDVvJAW8jePX9SEuU=; b=MfZbrT4ViywnxJJxI5RUGrXsKt6LTBQZ57s5rSBUFj38Rmklg69A5dBFT5HdCgQeTg3hBYhVGFx+iB6czAn3Cvg2HD/bKzjabCcCR/1xJCFwHExacvPiOHmNpX1lZ6xaicD7+WetpbRVk6h4gI4EwY0adbrdSd/2PXirVYoFyfk= 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 1675180986782313.44051212578313; Tue, 31 Jan 2023 08:03:06 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-urbyYY3QM_CKGJ7wxO1Law-1; Tue, 31 Jan 2023 11:02:42 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B4E02807D89; Tue, 31 Jan 2023 16:02:32 +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 7DEA6492B0D; Tue, 31 Jan 2023 16:02:32 +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 F0D961946A41; Tue, 31 Jan 2023 16:02:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0CD731946587 for ; Tue, 31 Jan 2023 16:02:31 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D61544010E36; Tue, 31 Jan 2023 16:02:30 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4300C401531C for ; Tue, 31 Jan 2023 16:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675180985; 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=Pz7py1yRnd9M8sizrsvQDuDDajPDVvJAW8jePX9SEuU=; b=azFcdDtJ1sr8WeW9SxElXP1zNdmq9mReFEEJZ8ERwBsPIBugXaLwgG9FJ5bJLZ14H+EUvY HcoCKxdP2Od3/6H+YIThgNl/oZjdAVh/VC9VoPeKWM3WI8l11H3TwsLuOvZo2AhuK/u9c/ s3AEeYUuU2rxQhwTfMngWdd30HnRcl0= X-MC-Unique: urbyYY3QM_CKGJ7wxO1Law-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/7] virStorageBackendISCSISetAuth: Use g_strndup to '\0' terminate data Date: Tue, 31 Jan 2023 17:02:15 +0100 Message-Id: <7af95e8b02d5d12d7e407cfaaf84a06f568c4e79.1675180728.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.9 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: 1675180987175100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/storage/storage_backend_iscsi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_back= end_iscsi.c index e4fa49d05f..01900f6809 100644 --- a/src/storage/storage_backend_iscsi.c +++ b/src/storage/storage_backend_iscsi.c @@ -283,10 +283,8 @@ virStorageBackendISCSISetAuth(const char *portal, &secret_value, &secret_size) < 0) return -1; - secret_str =3D g_new0(char, secret_size + 1); - memcpy(secret_str, secret_value, secret_size); + secret_str =3D g_strndup((char *) secret_value, secret_size); virSecureErase(secret_value, secret_size); - secret_str[secret_size] =3D '\0'; if (virISCSINodeUpdate(portal, source->devices[0].path, --=20 2.39.1 From nobody Sun May 19 08:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1675180971; cv=none; d=zohomail.com; s=zohoarc; b=Kp+BWFxFMcrvYC2405n8A4bPoT+/pOFtxZXzD7ov9kRSyRU9Ys21IvSVY+v1tS3QRQvvBPrnM+IwLu46MGdD1LJfTIz7/ZKiryHcJjQHYSnKx8hsT5Txk4vqtSBrNTbTAvj5jLg/qDRGaoxrfMiK7TrgRjZRm6C9M8pfsZPrb+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675180971; 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=YmZrG9PuhL7JRg2pu9D6eU7UpxNyhdDjP0cASceK2U0=; b=fWNn13rW0JXsPefQBwGpUTIrSjjk8/dPFbYL2OWRvfyxUQYrvoxxbw15Yd4ms4Xo80gWLY/oGvDQdW/WUMsC+YJlBAAcqdUSqvkIzRdke01oSAa3lzAC2tIeuBEHzhof/ASuvqFcT4ILhb9qFmUyABAXlJbhNpcq7l8JqBbOnSE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1675180971289548.2707308459302; Tue, 31 Jan 2023 08:02:51 -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-176-iz1p36_DOWCpjbGtv14COg-1; Tue, 31 Jan 2023 11:02:43 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B65881DB86; Tue, 31 Jan 2023 16:02:33 +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 5146140C2064; Tue, 31 Jan 2023 16:02:33 +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 38CFB1946589; Tue, 31 Jan 2023 16:02:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 16E0A1946A47 for ; Tue, 31 Jan 2023 16:02:32 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F01E14010E36; Tue, 31 Jan 2023 16:02:31 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AFFF40C141B for ; Tue, 31 Jan 2023 16:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675180970; 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=YmZrG9PuhL7JRg2pu9D6eU7UpxNyhdDjP0cASceK2U0=; b=P05WZt/HE7o5FXHsYn4t4t3TKrZdpBx0l8PcFOjCla8qcDZJh5aCr3F0cuqpoAK10ceufX 5tqi3kEhZM+Uhu6b2EW+YnXFKKXSsTBaVsAx22yNDy+Jzs2A8yLROfRjh1LALT3TllbmZU P7sO7XjgcxkR2MhqxWb9zrlYBU4QsGw= X-MC-Unique: iz1p36_DOWCpjbGtv14COg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/7] virStorageBackendISCSIDirectSetAuth: Refactor cleanup Date: Tue, 31 Jan 2023 17:02:16 +0100 Message-Id: <311ae7c5edaf8f62ec3845aae91144a882f6b2f0.1675180728.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.1 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: 1675180973112100006 Content-Type: text/plain; charset="utf-8" Use automatic pointer for 'conn' and remove the 'cleanup' label and 'ret' variable. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/storage/storage_backend_iscsi_direct.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 5df5447066..63225c533e 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -91,8 +91,7 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_context = *iscsi, size_t secret_size; g_autofree char *secret_str =3D NULL; virStorageAuthDef *authdef =3D source->auth; - int ret =3D -1; - virConnectPtr conn =3D NULL; + g_autoptr(virConnect) conn =3D NULL; VIR_IDENTITY_AUTORESTORE virIdentity *oldident =3D NULL; if (!authdef || authdef->authType =3D=3D VIR_STORAGE_AUTH_TYPE_NONE) @@ -104,19 +103,19 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_cont= ext *iscsi, if (authdef->authType !=3D VIR_STORAGE_AUTH_TYPE_CHAP) { virReportError(VIR_ERR_XML_ERROR, "%s", _("iscsi-direct pool only supports 'chap' auth type= ")); - return ret; + return -1; } if (!(oldident =3D virIdentityElevateCurrent())) return -1; if (!(conn =3D virGetConnectSecret())) - return ret; + return -1; if (virSecretGetSecretString(conn, &authdef->seclookupdef, VIR_SECRET_USAGE_TYPE_ISCSI, &secret_value, &secret_size) < 0) - goto cleanup; + return -1; secret_str =3D g_new0(char, secret_size + 1); memcpy(secret_str, secret_value, secret_size); @@ -125,17 +124,15 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_cont= ext *iscsi, if (iscsi_set_initiator_username_pwd(iscsi, authdef->username, secret_str) < = 0) { + virSecureErase(secret_str, secret_size); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to set credential: %s"), iscsi_get_error(iscsi)); - goto cleanup; + return -1; } - - ret =3D 0; - cleanup: virSecureErase(secret_str, secret_size); - virObjectUnref(conn); - return ret; + + return 0; } static int --=20 2.39.1 From nobody Sun May 19 08:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1675180970; cv=none; d=zohomail.com; s=zohoarc; b=JpLYfpENQrY8AxUrm1m/JQAl0cC/g8fg2VIS5ZLdzs0tx5R4dXEa2BdrgaooCWeyn09DLzrIHRNcDA5COaZt2Wyp+OD6gc+C2L4uKTXtQYlWNSjGMfg77M9jl+UnAa+fIMmGVoDmxRvGj/uPgXm9A4lzA2tmvU7UHCz7UmnQbSo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675180970; 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=nzjo7C+Z7e+5ZrcI2M3e/uKLYhat9A4DuHuz45/JBGw=; b=PV9qQiuxa0FWocGN0BoxVspdsutm6J77rqC+ZXCYf0v4n1ofDInpsq26+XMY+X+HoaBLnMZVVsUGV+FbA0V6pvdpExE3iILGZXh0QqHjA7kp+t2Nhs7tv68ycL/jWBykhXNkyEleZwLIk+TCHnhDCkG0NEw0wVwA/A3Y0JaZBq4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1675180970368474.4142667528291; Tue, 31 Jan 2023 08:02:50 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-376-xJ_-vuKZNE-hv6MEBMgTWw-1; Tue, 31 Jan 2023 11:02:45 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E030E1C0040D; Tue, 31 Jan 2023 16:02:33 +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 C83642026D4B; Tue, 31 Jan 2023 16:02:33 +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 B97221946589; Tue, 31 Jan 2023 16:02:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 10A871946587 for ; Tue, 31 Jan 2023 16:02:33 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0221740ED76B; Tue, 31 Jan 2023 16:02:33 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E5F440C1073 for ; Tue, 31 Jan 2023 16:02:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675180969; 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=nzjo7C+Z7e+5ZrcI2M3e/uKLYhat9A4DuHuz45/JBGw=; b=Xh4pkLSr2NEA+8Kxgwk/RdTQLG9Teluj7KDVJGEXKoOsJbRHjWmSAqvn/J8Mfhsp0YqM6T fug25Ds3fN0dWAO41GE+6mTtaLzATr1xeu27E/AgfFOwnVotstGf7mSTMMP7kjYMaQHjo3 UzswXn8XYtDxTQnKZZm8UcdRWuj4fBc= X-MC-Unique: xJ_-vuKZNE-hv6MEBMgTWw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/7] virStorageBackendISCSIDirectSetAuth: Use 'g_strndup' to '\0' terminate data Date: Tue, 31 Jan 2023 17:02:17 +0100 Message-Id: <7405f4a52dc0bc4f62b6a2dfcb980e1700867406.1675180728.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.4 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: 1675180971327100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/storage/storage_backend_iscsi_direct.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/stora= ge_backend_iscsi_direct.c index 63225c533e..ca906357c3 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -117,10 +117,8 @@ virStorageBackendISCSIDirectSetAuth(struct iscsi_conte= xt *iscsi, &secret_value, &secret_size) < 0) return -1; - secret_str =3D g_new0(char, secret_size + 1); - memcpy(secret_str, secret_value, secret_size); + secret_str =3D g_strndup((char *)secret_value, secret_size); virSecureErase(secret_value, secret_size); - secret_str[secret_size] =3D '\0'; if (iscsi_set_initiator_username_pwd(iscsi, authdef->username, secret_str) < = 0) { --=20 2.39.1 From nobody Sun May 19 08:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1675181004; cv=none; d=zohomail.com; s=zohoarc; b=HpJLUDpHy0Fjy5trE+T9OKlE3omjIGHsa/Y+/d7S/DdsZcuMUqLEBt4RqWeIznapbpsn8Bm7gydmt07xx2pWMHRk7j1dwV4vsMZX0DQ8WZEIKIa9i/XN0ot10ORUWlIhL54TzFSs9patXkVkoybigQPT0wyWkDX5Kol5FfUJRL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675181004; 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=KLTSXoYVY00VeRFZ+OVH4oFuvvUqiQNjTBk4VlW1B6w=; b=DINEdIe9ynhw0yrM9hscgEx3aSswTXonLII/TOi0TsbCiwMZtIXeM5XFTUxtldWxe9FQcdjFNFAfJ9FxXinxo2xlNlKFoHLwIiSGIZCG8VqtYoBJOYJfr3EivQ9F+nCNCwObCd8YAKGtnH2mxB00/1cQOGE0IxLCIh+uBqTijms= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1675181004607933.9361253723441; Tue, 31 Jan 2023 08:03:24 -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-554-VtGBn4_EPK2c62blvb6VTw-1; Tue, 31 Jan 2023 11:02:48 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 92812857A81; Tue, 31 Jan 2023 16:02:35 +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 7BA092026D4B; Tue, 31 Jan 2023 16:02:35 +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 7166D1946589; Tue, 31 Jan 2023 16:02:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1B9F21946594 for ; Tue, 31 Jan 2023 16:02:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F2A134015319; Tue, 31 Jan 2023 16:02:33 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6912E40C141B for ; Tue, 31 Jan 2023 16:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675181003; 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=KLTSXoYVY00VeRFZ+OVH4oFuvvUqiQNjTBk4VlW1B6w=; b=DE+W6Yf2Y7B53lILpBZZXPQwWR4QCgwCbalFqjgqQEHyYX2meqZP8tgTkZlGjzvqeZGAHS qj+I8LWIzk4c1LBpeROaRTJ4BgUa09WPZ/xhfRGND1/dSil7cS/uS/mGFtNKQnzpTScO3j G1NJfdgGzlPCdtzPesLbFl4Ibs9oI7c= X-MC-Unique: VtGBn4_EPK2c62blvb6VTw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/7] libxlMakeNetworkDiskSrc: Refactor cleanup Date: Tue, 31 Jan 2023 17:02:18 +0100 Message-Id: <26043c0c7d0c9f4c6867d328e3784741fa80cf2e.1675180728.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.4 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: 1675181005331100001 Content-Type: text/plain; charset="utf-8" Automatically unref the 'conn' object and remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/libxl/libxl_conf.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 17ac880634..cee9f827f7 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1026,10 +1026,9 @@ libxlMakeNetworkDiskSrcStr(virStorageSource *src, static int libxlMakeNetworkDiskSrc(virStorageSource *src, char **srcstr) { - virConnectPtr conn =3D NULL; + g_autoptr(virConnect) conn =3D NULL; g_autofree char *base64secret =3D NULL; char *username =3D NULL; - int ret =3D -1; *srcstr =3D NULL; if (src->auth && src->protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_RBD) { @@ -1038,16 +1037,16 @@ libxlMakeNetworkDiskSrc(virStorageSource *src, char= **srcstr) VIR_IDENTITY_AUTORESTORE virIdentity *oldident =3D virIdentityElev= ateCurrent(); if (!oldident) - goto cleanup; + return -1; username =3D src->auth->username; if (!(conn =3D virConnectOpen("xen:///system"))) - goto cleanup; + return -1; if (virSecretGetSecretString(conn, &src->auth->seclookupdef, VIR_SECRET_USAGE_TYPE_CEPH, &secret, &secretlen) < 0) - goto cleanup; + return -1; /* RBD expects an encoded secret */ base64secret =3D g_base64_encode(secret, secretlen); @@ -1058,13 +1057,9 @@ libxlMakeNetworkDiskSrc(virStorageSource *src, char = **srcstr) virSecureEraseString(base64secret); if (!*srcstr) - goto cleanup; - - ret =3D 0; + return -1; - cleanup: - virObjectUnref(conn); - return ret; + return 0; } int --=20 2.39.1 From nobody Sun May 19 08:26:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1675180983; cv=none; d=zohomail.com; s=zohoarc; b=n5F0CPla/aD2hMNz/P9O/CGhUValwlVgpXIGtzzQnjs/RoctTIoD+7cmftZuPmwAWobLsMhQ3B9z+JecylL7kbYdrIL+/fDgMSvHD83jtNosAVo8d10Ko9XlkVYYPbh2XirhZluluP5ZefeTapzOXe7Nr4k38UMZnEjMfLT7VFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675180983; 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=jK0vhRoLSXILucWIwpghkKIirxc0A8d5kSr/sJ5bfOY=; b=CLjmc2NRRijqUdZysOo/f1vIUJy86W0AxbNjgKr018zMvEwHSRGB9JA9qfVDWh1OHQkxlM8sfK+1zZBZWW29Zo25YliUKw4mWGQOMM4NhMuNaTt95JYTQu8BR6TOyRo9AgaVk9+dVwcni2/yyOnfywxdma4CRd35w8TtPrjQnCc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1675180983468884.75414402731; Tue, 31 Jan 2023 08:03:03 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-Ra07JpKFPSOzNs-B-nDRog-1; Tue, 31 Jan 2023 11:02:59 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 407112805584; Tue, 31 Jan 2023 16:02:37 +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 2B7AC492C3E; Tue, 31 Jan 2023 16:02:37 +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 0C7391946589; Tue, 31 Jan 2023 16:02:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 08AFE1946597 for ; Tue, 31 Jan 2023 16:02:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F150F4085721; Tue, 31 Jan 2023 16:02:34 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53FEB4085720 for ; Tue, 31 Jan 2023 16:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675180982; 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=jK0vhRoLSXILucWIwpghkKIirxc0A8d5kSr/sJ5bfOY=; b=JQmgYVWbCANuBpanJqcA0/H4NGiUL5q4q0KfQgVjMd/dhvghNj3bwE0/RsbHBs6+5I+9MF 5vy6DkGnpj5/VjyvpRj2JqOi+McOw+iKRzpqsqTT93S7/E4Kg+1y8TXlewYNw2rMO0kl7v QEN/mK2UlMNGkc1donRou0XVfflQJ4Q= X-MC-Unique: Ra07JpKFPSOzNs-B-nDRog-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 7/7] storageBackendCreateQemuImgSecretPath: Refactor cleanup Date: Tue, 31 Jan 2023 17:02:19 +0100 Message-Id: <10b9cd1aa3481cfa2308083a0bbf06d777fc9d3d.1675180728.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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.10 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: 1675180985154100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/storage/storage_util.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 520fdd03d0..b57128eb2e 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -1259,10 +1259,10 @@ storageBackendCreateQemuImgSecretPath(virStoragePoo= lObj *pool, virStorageVolDef *vol) { virStorageEncryption *enc =3D vol->target.encryption; - char *secretPath =3D NULL; - uint8_t *secret =3D NULL; + g_autofree char *secretPath =3D NULL; + g_autofree uint8_t *secret =3D NULL; size_t secretlen =3D 0; - virConnectPtr conn =3D NULL; + g_autoptr(virConnect) conn =3D NULL; VIR_AUTOCLOSE fd =3D -1; VIR_IDENTITY_AUTORESTORE virIdentity *oldident =3D NULL; @@ -1287,24 +1287,29 @@ storageBackendCreateQemuImgSecretPath(virStoragePoo= lObj *pool, return NULL; if (!(secretPath =3D virStoragePoolObjBuildTempFilePath(pool, vol))) - goto cleanup; + return NULL; if ((fd =3D g_mkstemp_full(secretPath, O_RDWR | O_CLOEXEC, S_IRUSR | S= _IWUSR)) < 0) { virReportSystemError(errno, "%s", _("failed to open secret file for write")); - goto error; + return NULL; } if (virSecretGetSecretString(conn, &enc->secrets[0]->seclookupdef, VIR_SECRET_USAGE_TYPE_VOLUME, - &secret, &secretlen) < 0) - goto error; + &secret, &secretlen) < 0) { + unlink(secretPath); + return NULL; + } if (safewrite(fd, secret, secretlen) < 0) { + virSecureErase(secret, secretlen); virReportSystemError(errno, "%s", _("failed to write secret file")); - goto error; + unlink(secretPath); + return NULL; } + virSecureErase(secret, secretlen); if ((vol->target.perms->uid !=3D (uid_t)-1) && (vol->target.perms->gid !=3D (gid_t)-1)) { @@ -1312,21 +1317,12 @@ storageBackendCreateQemuImgSecretPath(virStoragePoo= lObj *pool, vol->target.perms->gid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to chown secret file")); - goto error; + unlink(secretPath); + return NULL; } } - cleanup: - virObjectUnref(conn); - virSecureErase(secret, secretlen); - g_free(secret); - - return secretPath; - - error: - unlink(secretPath); - VIR_FREE(secretPath); - goto cleanup; + return g_steal_pointer(&secretPath); } --=20 2.39.1