Permalink
Browse files

Fix check for linux getrandom syscall

  • Loading branch information...
lt authored and nikic committed Dec 23, 2015
1 parent 9ad3413 commit 14c72cc5824d5fa472b79b7216a01be0918ccc5d
Showing with 1 addition and 6 deletions.
  1. +0 −5 ext/standard/config.m4
  2. +1 −1 ext/standard/random.c
@@ -607,11 +607,6 @@ dnl Check for arc4random on BSD systems
dnl
AC_CHECK_DECLS([arc4random_buf])
dnl
dnl Check for getrandom on newer Linux kernels
dnl
AC_CHECK_DECLS([getrandom])
dnl
dnl Setup extension sources
dnl
@@ -93,7 +93,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, zend_bool should_throw)
}
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001))
arc4random_buf(bytes, size);
#elif HAVE_DECL_GETRANDOM
#elif defined(__linux__) && defined(SYS_getrandom)
/* Linux getrandom(2) syscall */
size_t read_bytes = 0;
size_t amount_to_read = 0;

5 comments on commit 14c72cc

@mathieubruno

This comment has been minimized.

mathieubruno replied Feb 15, 2017

This patch makes php unusable on older kernel, if it is compiled on newer kernel.
PHP throws "Uncaught Exception: Could not gather sufficient random data" on kernels with /dev/urandom but without getrandom if it has been compiled on newer kernel, because after the 116th line of random.c, there is no check for ENOSYS errno.
see here for example

@jderusse

This comment has been minimized.

jderusse replied Feb 20, 2017

same error for docker alpine images. see docker-library/php#376

@nikic

This comment has been minimized.

Member

nikic replied Feb 20, 2017

Already fixed by #2385.

@jderusse

This comment has been minimized.

jderusse replied Feb 20, 2017

@nikic this PR was merged against master... whereas the bug is in 7.0 :(

@nikic

This comment has been minimized.

Member

nikic replied Feb 20, 2017

It's merged into 7.0+. I'm not sure why, but Github often computes branch membership incorrectly.

Please sign in to comment.