rand_unix.c: Ensure requests to KERN_ARND don't exceed 256 bytes.
authornia <nia@netbsd.org>
Thu, 30 Apr 2020 13:43:04 +0000 (14:43 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 4 May 2020 08:04:41 +0000 (09:04 +0100)
Requests for more than 256 bytes will fail.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11689)

(cherry picked from commit 7421f085005e0d7a1dd2fe61b991ff23cef91c22)

crypto/rand/rand_unix.c

index 177ee6958f9d1394561580f5252e0f3740bbb117..19b6138a1f12387c44868462c547a897345468ce 100644 (file)
@@ -270,7 +270,7 @@ static ssize_t sysctl_random(char *buf, size_t buflen)
     mib[1] = KERN_ARND;
 
     do {
-        len = buflen;
+        len = buflen > 256 ? 256 : buflen;
         if (sysctl(mib, 2, buf, &len, NULL, 0) == -1)
             return done > 0 ? done : -1;
         done += len;