From: Michael Braun Date: Fri, 18 Aug 2017 16:55:17 +0000 (+0200) Subject: crypto: Fix undefined behavior in random number generator X-Git-Tag: hostap_2_7~1123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=333517ac1c558f36114351193889397712905a85;p=thirdparty%2Fhostap.git crypto: Fix undefined behavior in random number generator ubsan reported: ../src/crypto/random.c:69:30: runtime error: shift exponent 32 is too large for 32-bit type 'unsigned int' Explicitly check for the ROL32(x, 0) case which is supposed to be a no-op. Signed-off-by: Michael Braun --- diff --git a/src/crypto/random.c b/src/crypto/random.c index 3a86a93a4..fb9241762 100644 --- a/src/crypto/random.c +++ b/src/crypto/random.c @@ -66,6 +66,9 @@ static void random_write_entropy(void); static u32 __ROL32(u32 x, u32 y) { + if (y == 0) + return x; + return (x << (y & 31)) | (x >> (32 - (y & 31))); }