render / rpms / libvirt

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