From nobody Wed May 14 17:10:18 2025 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1527582343572181.7445466770331; Tue, 29 May 2018 01:25:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36E1CC081F49; Tue, 29 May 2018 08:25:42 +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 F35AE608F6; Tue, 29 May 2018 08:25:41 +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 A741B1800FED; Tue, 29 May 2018 08:25:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4T8PInH005804 for ; Tue, 29 May 2018 04:25:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4CCBE63F6A; Tue, 29 May 2018 08:25:18 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7DB463F53; Tue, 29 May 2018 08:25:17 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 29 May 2018 10:24:45 +0200 Message-Id: <029f656de7228ec02f147fc060e50be917ce9e60.1527581861.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/10] virUUIDGenerate don't fall back to virRandomBits 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 29 May 2018 08:25:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If virRandomBytes() fails there is no point calling virRandomBits() because it uses virRandomBytes() internally again. Signed-off-by: Michal Privoznik --- src/util/viruuid.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/util/viruuid.c b/src/util/viruuid.c index 61877aeba4..f588a62ec6 100644 --- a/src/util/viruuid.c +++ b/src/util/viruuid.c @@ -48,18 +48,6 @@ VIR_LOG_INIT("util.uuid"); =20 static unsigned char host_uuid[VIR_UUID_BUFLEN]; =20 -static int -virUUIDGeneratePseudoRandomBytes(unsigned char *buf, - int buflen) -{ - while (buflen > 0) { - *buf++ =3D virRandomBits(8); - buflen--; - } - - return 0; -} - /** * virUUIDGenerate: * @uuid: array of VIR_UUID_BUFLEN bytes to store the new UUID @@ -71,18 +59,11 @@ virUUIDGeneratePseudoRandomBytes(unsigned char *buf, int virUUIDGenerate(unsigned char *uuid) { - int err; - if (uuid =3D=3D NULL) return -1; =20 - if ((err =3D virRandomBytes(uuid, VIR_UUID_BUFLEN)) < 0) { - char ebuf[1024]; - VIR_WARN("Falling back to pseudorandom UUID," - " failed to generate random bytes: %s", - virStrerror(-err, ebuf, sizeof(ebuf))); - err =3D virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_BUFLEN); - } + if (virRandomBytes(uuid, VIR_UUID_BUFLEN) < 0) + return -1; =20 /* * Make UUID RFC 4122 compliant. Following form will be used: @@ -103,7 +84,7 @@ virUUIDGenerate(unsigned char *uuid) uuid[6] =3D (uuid[6] & 0x0F) | (4 << 4); uuid[8] =3D (uuid[8] & 0x3F) | (2 << 6); =20 - return err; + return 0; } =20 /** --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list