Hans Leidekker : ntdll: Fall back to reading /dev/urandom if getrandom() is not supported.
Alexandre Julliard
julliard at winehq.org
Tue Mar 16 16:39:03 CDT 2021
Module: wine
Branch: master
Commit: e6407c39bab62838081f30868cb2ac1362029bdf
URL: https://source.winehq.org/git/wine.git/?a=commit;h=e6407c39bab62838081f30868cb2ac1362029bdf
Author: Hans Leidekker <hans at codeweavers.com>
Date: Tue Mar 16 09:46:48 2021 +0100
ntdll: Fall back to reading /dev/urandom if getrandom() is not supported.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50168
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/unix/system.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c
index 48321957fb8..6fa71ddfb91 100644
--- a/dlls/ntdll/unix/system.c
+++ b/dlls/ntdll/unix/system.c
@@ -2036,6 +2036,22 @@ static void get_timezone_info( RTL_DYNAMIC_TIME_ZONE_INFORMATION *tzi )
}
+static void read_dev_urandom( void *buf, ULONG len )
+{
+ int fd = open( "/dev/urandom", O_RDONLY );
+ if (fd != -1)
+ {
+ int ret;
+ do
+ {
+ ret = read( fd, buf, len );
+ }
+ while (ret == -1 && errno == EINTR);
+ close( fd );
+ }
+ else WARN( "can't open /dev/urandom\n" );
+}
+
/******************************************************************************
* NtQuerySystemInformation (NTDLL.@)
*/
@@ -2525,19 +2541,10 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
ret = getrandom( info, len, 0 );
}
while (ret == -1 && errno == EINTR);
+
+ if (ret == -1 && errno == ENOSYS) read_dev_urandom( info, len );
#else
- int fd = open( "/dev/urandom", O_RDONLY );
- if (fd != -1)
- {
- int ret;
- do
- {
- ret = read( fd, info, len );
- }
- while (ret == -1 && errno == EINTR);
- close( fd );
- }
- else WARN( "can't open /dev/urandom\n" );
+ read_dev_urandom( info, len );
#endif
}
}
More information about the wine-cvs
mailing list