From nobody Wed Feb 11 07:09:25 2026 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.zoho.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 1493056859052517.0097388078182; Mon, 24 Apr 2017 11:00:59 -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 1B15FC05975A; Mon, 24 Apr 2017 18:00:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E683C81F81; Mon, 24 Apr 2017 18:00:56 +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 EA2F65EC71; Mon, 24 Apr 2017 18:00:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3OI0abI004720 for ; Mon, 24 Apr 2017 14:00:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 36B5C77ECA; Mon, 24 Apr 2017 18:00:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01CD317A7B for ; Mon, 24 Apr 2017 18:00:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1B15FC05975A 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=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1B15FC05975A From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:15 -0400 Message-Id: <20170424180023.4695-7-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/14] secret: Use virSecretDefPtr rather than deref from virSecretObjPtr 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]); Mon, 24 Apr 2017 18:00:57 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than dereferencing obj->def->X, create a local 'def' variable variable that will dereference the def and use directly. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 69 +++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 42f36c8..413955d 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -139,8 +139,9 @@ static void virSecretObjDispose(void *opaque) { virSecretObjPtr obj =3D opaque; + virSecretDefPtr def =3D obj->def; =20 - virSecretDefFree(obj->def); + virSecretDefFree(def); if (obj->value) { /* Wipe before free to ensure we don't leave a secret on the heap = */ memset(obj->value, 0, obj->value_size); @@ -203,16 +204,18 @@ virSecretObjSearchName(const void *payload, const void *opaque) { virSecretObjPtr obj =3D (virSecretObjPtr) payload; + virSecretDefPtr def; struct virSecretSearchData *data =3D (struct virSecretSearchData *) op= aque; int found =3D 0; =20 virObjectLock(obj); + def =3D obj->def; =20 - if (obj->def->usage_type !=3D data->usageType) + if (def->usage_type !=3D data->usageType) goto cleanup; =20 if (data->usageType !=3D VIR_SECRET_USAGE_TYPE_NONE && - STREQ(obj->def->usage_id, data->usageID)) + STREQ(def->usage_id, data->usageID)) found =3D 1; =20 cleanup: @@ -278,11 +281,13 @@ virSecretObjListRemove(virSecretObjListPtr secrets, virSecretObjPtr obj) { char uuidstr[VIR_UUID_STRING_BUFLEN]; + virSecretDefPtr def; =20 if (!obj) return; + def =3D obj->def; =20 - virUUIDFormat(obj->def->uuid, uuidstr); + virUUIDFormat(def->uuid, uuidstr); virObjectRef(obj); virObjectUnlock(obj); =20 @@ -315,6 +320,7 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, virSecretDefPtr *oldDef) { virSecretObjPtr obj; + virSecretDefPtr def; virSecretObjPtr ret =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; char *configFile =3D NULL, *base64File =3D NULL; @@ -325,26 +331,27 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, /* Is there a secret already matching this UUID */ if ((obj =3D virSecretObjListFindByUUIDLocked(secrets, newdef->uuid)))= { virObjectLock(obj); + def =3D obj->def; =20 - if (STRNEQ_NULLABLE(obj->def->usage_id, newdef->usage_id)) { - virUUIDFormat(obj->def->uuid, uuidstr); + if (STRNEQ_NULLABLE(def->usage_id, newdef->usage_id)) { + virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s is already defined for= " "use with %s"), - uuidstr, obj->def->usage_id); + uuidstr, def->usage_id); goto cleanup; } =20 - if (obj->def->isprivate && !newdef->isprivate) { + if (def->isprivate && !newdef->isprivate) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot change private flag on existing secre= t")); goto cleanup; } =20 if (oldDef) - *oldDef =3D obj->def; + *oldDef =3D def; else - virSecretDefFree(obj->def); + virSecretDefFree(def); obj->def =3D newdef; } else { /* No existing secret with same UUID, @@ -353,7 +360,8 @@ virSecretObjListAddLocked(virSecretObjListPtr secrets, newdef->usage_type, newdef->usage_id))) { virObjectLock(obj); - virUUIDFormat(obj->def->uuid, uuidstr); + def =3D obj->def; + virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_INTERNAL_ERROR, _("a secret with UUID %s already defined for " "use with %s"), @@ -424,6 +432,7 @@ virSecretObjListGetHelper(void *payload, { struct virSecretObjListGetHelperData *data =3D opaque; virSecretObjPtr obj =3D payload; + virSecretDefPtr def; =20 if (data->error) return 0; @@ -432,8 +441,9 @@ virSecretObjListGetHelper(void *payload, return 0; =20 virObjectLock(obj); + def =3D obj->def; =20 - if (data->filter && !data->filter(data->conn, obj->def)) + if (data->filter && !data->filter(data->conn, def)) goto cleanup; =20 if (data->uuids) { @@ -444,7 +454,7 @@ virSecretObjListGetHelper(void *payload, goto cleanup; } =20 - virUUIDFormat(obj->def->uuid, uuidstr); + virUUIDFormat(def->uuid, uuidstr); data->uuids[data->got] =3D uuidstr; } =20 @@ -478,20 +488,22 @@ static bool virSecretObjMatchFlags(virSecretObjPtr obj, unsigned int flags) { + virSecretDefPtr def =3D obj->def; + /* filter by whether it's ephemeral */ if (MATCH(VIR_CONNECT_LIST_SECRETS_FILTERS_EPHEMERAL) && !((MATCH(VIR_CONNECT_LIST_SECRETS_EPHEMERAL) && - obj->def->isephemeral) || + def->isephemeral) || (MATCH(VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL) && - !obj->def->isephemeral))) + !def->isephemeral))) return false; =20 /* filter by whether it's private */ if (MATCH(VIR_CONNECT_LIST_SECRETS_FILTERS_PRIVATE) && !((MATCH(VIR_CONNECT_LIST_SECRETS_PRIVATE) && - obj->def->isprivate) || + def->isprivate) || (MATCH(VIR_CONNECT_LIST_SECRETS_NO_PRIVATE) && - !obj->def->isprivate))) + !def->isprivate))) return false; =20 return true; @@ -515,14 +527,16 @@ virSecretObjListPopulate(void *payload, { struct virSecretObjListData *data =3D opaque; virSecretObjPtr obj =3D payload; + virSecretDefPtr def; virSecretPtr secret =3D NULL; =20 if (data->error) return 0; =20 virObjectLock(obj); + def =3D obj->def; =20 - if (data->filter && !data->filter(data->conn, obj->def)) + if (data->filter && !data->filter(data->conn, def)) goto cleanup; =20 if (!virSecretObjMatchFlags(obj, data->flags)) @@ -533,9 +547,9 @@ virSecretObjListPopulate(void *payload, goto cleanup; } =20 - if (!(secret =3D virGetSecret(data->conn, obj->def->uuid, - obj->def->usage_type, - obj->def->usage_id))) { + if (!(secret =3D virGetSecret(data->conn, def->uuid, + def->usage_type, + def->usage_id))) { data->error =3D true; goto cleanup; } @@ -624,7 +638,9 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, int virSecretObjDeleteConfig(virSecretObjPtr obj) { - if (!obj->def->isephemeral && + virSecretDefPtr def =3D obj->def; + + if (!def->isephemeral && unlink(obj->configFile) < 0 && errno !=3D ENOENT) { virReportSystemError(errno, _("cannot unlink '%s'"), obj->configFile); @@ -653,10 +669,11 @@ virSecretObjDeleteData(virSecretObjPtr obj) int virSecretObjSaveConfig(virSecretObjPtr obj) { + virSecretDefPtr def =3D obj->def; char *xml =3D NULL; int ret =3D -1; =20 - if (!(xml =3D virSecretDefFormat(obj->def))) + if (!(xml =3D virSecretDefFormat(def))) goto cleanup; =20 if (virFileRewriteStr(obj->configFile, S_IRUSR | S_IWUSR, xml) < 0) @@ -711,11 +728,12 @@ virSecretObjSetDef(virSecretObjPtr obj, unsigned char * virSecretObjGetValue(virSecretObjPtr obj) { + virSecretDefPtr def =3D obj->def; unsigned char *ret =3D NULL; =20 if (!obj->value) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(obj->def->uuid, uuidstr); + virUUIDFormat(def->uuid, uuidstr); virReportError(VIR_ERR_NO_SECRET, _("secret '%s' does not have a value"), uuidstr); goto cleanup; @@ -735,6 +753,7 @@ virSecretObjSetValue(virSecretObjPtr obj, const unsigned char *value, size_t value_size) { + virSecretDefPtr def =3D obj->def; unsigned char *old_value, *new_value; size_t old_value_size; =20 @@ -748,7 +767,7 @@ virSecretObjSetValue(virSecretObjPtr obj, obj->value =3D new_value; obj->value_size =3D value_size; =20 - if (!obj->def->isephemeral && virSecretObjSaveData(obj) < 0) + if (!def->isephemeral && virSecretObjSaveData(obj) < 0) goto error; =20 /* Saved successfully - drop old value */ --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list