]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
crypto: Fix undefined behavior in random number generator
authorMichael Braun <michael-dev@fami-braun.de>
Fri, 18 Aug 2017 16:55:17 +0000 (18:55 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 10 Sep 2017 18:50:21 +0000 (21:50 +0300)
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 <michael-dev@fami-braun.de>
src/crypto/random.c

index 3a86a93a46a8bbe56fbc0fd5681fe1827af0fd2f..fb92417621ef500f8d68ad5967ad913907638c7c 100644 (file)
@@ -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)));
 }