From 7407e5ecdb06875f6289d026b2876663fc598f49 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Sun, 23 Jun 2019 13:11:07 -0700 Subject: [PATCH] Check for EPERM on getrandom support detection --- src/linux_android.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/linux_android.rs b/src/linux_android.rs index 11e06184..f5825aca 100644 --- a/src/linux_android.rs +++ b/src/linux_android.rs @@ -45,10 +45,13 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> { } fn is_getrandom_available() -> bool { - let mut buf: [u8; 0] = []; - match syscall_getrandom(&mut buf, false) { + match syscall_getrandom(&mut [], false) { + Err(err) => match err.raw_os_error() { + Some(libc::ENOSYS) => false, // No kernel support + Some(libc::EPERM) => false, // Blocked by seccomp + _ => true, + } Ok(_) => true, - Err(err) => err.raw_os_error() != Some(libc::ENOSYS), } }