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