render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
630768
From cdd5c75a34654abb2516476b851c6730b4bcb11b Mon Sep 17 00:00:00 2001
630768
Message-Id: <cdd5c75a34654abb2516476b851c6730b4bcb11b@dist-git>
630768
From: Michal Privoznik <mprivozn@redhat.com>
630768
Date: Mon, 21 Jan 2019 09:04:11 -0500
630768
Subject: [PATCH] virrandom: Avoid undefined behaviour in virRandomBits
630768
MIME-Version: 1.0
630768
Content-Type: text/plain; charset=UTF-8
630768
Content-Transfer-Encoding: 8bit
630768
630768
https://bugzilla.redhat.com/show_bug.cgi?id=1667329 (RHEL 7.6.z)
630768
https://bugzilla.redhat.com/show_bug.cgi?id=1652894 (RHEL 7.7)
630768
630768
If nbits is 64 (or greater) then shifting 1ULL left is undefined.
630768
630768
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
630768
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
630768
(cherry picked from commit 0a5a6f0d019996b015bb0acbe30efa8f2fbbb351)
630768
Signed-off-by: John Ferlan <jferlan@redhat.com>
630768
Message-Id: <20190121140412.27804-3-jferlan@redhat.com>
630768
Reviewed-by: Erik Skultety <eskultet@redhat.com>
630768
---
630768
 src/util/virrandom.c | 4 +++-
630768
 1 file changed, 3 insertions(+), 1 deletion(-)
630768
630768
diff --git a/src/util/virrandom.c b/src/util/virrandom.c
630768
index 3c011a8615..7915f6531e 100644
630768
--- a/src/util/virrandom.c
630768
+++ b/src/util/virrandom.c
630768
@@ -68,7 +68,9 @@ uint64_t virRandomBits(int nbits)
630768
         return 0;
630768
     }
630768
 
630768
-    ret &= (1ULL << nbits) - 1;
630768
+    if (nbits < 64)
630768
+        ret &= (1ULL << nbits) - 1;
630768
+
630768
     return ret;
630768
 }
630768
 
630768
-- 
630768
2.20.1
630768