]> xenbits.xensource.com Git - libvirt.git/commitdiff
virUUIDGenerate don't fall back to virRandomBits
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 29 May 2018 06:35:13 +0000 (08:35 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 5 Jun 2018 08:31:19 +0000 (10:31 +0200)
If virRandomBytes() fails there is no point calling
virRandomBits() because it uses virRandomBytes() internally
again.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/util/viruuid.c

index 61877aeba4fb5a6a5a2c9e515ee5048c21583f1b..f588a62ec6a6dd06ba5be692db04c94d0c79251b 100644 (file)
@@ -48,18 +48,6 @@ VIR_LOG_INIT("util.uuid");
 
 static unsigned char host_uuid[VIR_UUID_BUFLEN];
 
-static int
-virUUIDGeneratePseudoRandomBytes(unsigned char *buf,
-                                 int buflen)
-{
-    while (buflen > 0) {
-        *buf++ = 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 == NULL)
         return -1;
 
-    if ((err = 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 = virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_BUFLEN);
-    }
+    if (virRandomBytes(uuid, VIR_UUID_BUFLEN) < 0)
+        return -1;
 
     /*
      * Make UUID RFC 4122 compliant. Following form will be used:
@@ -103,7 +84,7 @@ virUUIDGenerate(unsigned char *uuid)
     uuid[6] = (uuid[6] & 0x0F) | (4 << 4);
     uuid[8] = (uuid[8] & 0x3F) | (2 << 6);
 
-    return err;
+    return 0;
 }
 
 /**