bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getrandom: Fail with ENOSYS when the system has no randomness source


From: Bruno Haible
Subject: getrandom: Fail with ENOSYS when the system has no randomness source
Date: Sun, 09 May 2021 16:51:49 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-206-generic; KDE/5.18.0; x86_64; ; )

On IRIX 6.5, 'test-getrandom' fails:

$ ./test-getrandom 
../../tests/test-getrandom.c:43: assertion 'errno == ENOSYS' failed

The glibc documentation
<https://www.gnu.org/software/libc/manual/html_node/Unpredictable-Bytes.html>
says that when "The operating system does not implement a randomness source"
the function should return with errno set to ENOSYS. This is what our unit
test is verifying. So, it's our getrandom() implementation that needs a fix.


2021-05-09  Bruno Haible  <bruno@clisp.org>

        getrandom: Fail with ENOSYS when the system has no randomness source.
        * lib/getrandom.c (getrandom): When open() fails, set errno to ENOSYS.

diff --git a/lib/getrandom.c b/lib/getrandom.c
index 41212fb..6160118 100644
--- a/lib/getrandom.c
+++ b/lib/getrandom.c
@@ -178,7 +178,10 @@ getrandom (void *buffer, size_t length, unsigned int flags)
                     + (flags & GRND_NONBLOCK ? O_NONBLOCK : 0));
       fd = open (randdevice[devrandom], oflags);
       if (fd < 0)
-        return fd;
+        {
+          errno = ENOSYS;
+          return -1;
+        }
       randfd[devrandom] = fd;
     }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]