]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
syscall_random(): don't fail if the getentropy() function is a dummy
authorYury Is <yury.coder@gmail.com>
Mon, 12 Oct 2020 23:28:26 +0000 (02:28 +0300)
committerDr. Matthias St. Pierre <matthias.st.pierre@ncp-e.com>
Wed, 14 Oct 2020 05:58:47 +0000 (07:58 +0200)
Several embedded toolchains may provide dummy implemented getentropy()
function which always returns -1 and sets errno to the ENOSYS.

As a result the function SSL_CTX_new() fails to create a new context.

Fixes #13002

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/13112)

crypto/rand/rand_unix.c

index da66773e4ab9135df2b8a2d3f7abf107f97d716d..ec6be791b37f445620a7dcd1077b9c3059c9b7e7 100644 (file)
@@ -365,12 +365,19 @@ static ssize_t syscall_random(void *buf, size_t buflen)
      * - OpenBSD since 5.6
      * - Linux since 3.17 with glibc 2.25
      * - FreeBSD since 12.0 (1200061)
+     *
+     * Note: Sometimes getentropy() can be provided but not implemented
+     * internally. So we need to check errno for ENOSYS
      */
 #  if defined(__GNUC__) && __GNUC__>=2 && defined(__ELF__) && !defined(__hpux)
     extern int getentropy(void *buffer, size_t length) __attribute__((weak));
 
-    if (getentropy != NULL)
-        return getentropy(buf, buflen) == 0 ? (ssize_t)buflen : -1;
+    if (getentropy != NULL) {
+        if (getentropy(buf, buflen) == 0)
+            return (ssize_t)buflen;
+        if (errno != ENOSYS)
+            return -1;
+    }
 #  else
     union {
         void *p;