com php-src: Fixed bug #70641 (Random_* - Better comp atibility on Linux distros): ext/standard/random. c
| From: | Bob Weinand | Date: | Mon, 05 Oct 2015 23:03:04 +0000 |
| Subject: | com php-src: Fixed bug #70641 (Random_* - Better comp atibility on Linux distros): ext/standard/random. c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89301@lists.php.net to get a copy of this message | ||
Commit: 63617a678f51d07d7e1843221afffe9a8b31c624
Author: Scott <scott@paragonie.com> Mon, 5 Oct 2015 11:39:55 -0400
Committer: Bob Weinand <bobwei9@hotmail.com> Tue, 6 Oct 2015 01:03:04 +0200
Parents: d5bd999a8f33144ffbd19d5d45ba078dc77242da
Branches: PHP-7.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=63617a678f51d07d7e1843221afffe9a8b31c624
Log:
Fixed bug #70641 (Random_* - Better compatibility on Linux distros)
See:
* https://bugs.php.net/bug.php?id=70641
* https://github.com/php/php-src/pull/1513#issuecomment-145571829
Bugs:
https://bugs.php.net/70641
Changed paths:
M ext/standard/random.c
Diff:
diff --git a/ext/standard/random.c b/ext/standard/random.c
index 6d3ec14..f46c4e0 100644
--- a/ext/standard/random.c
+++ b/ext/standard/random.c
@@ -31,7 +31,7 @@
# include "win32/winutil.h"
#endif
#ifdef __linux__
-# include <linux/random.h>
+# include <sys/syscall.h>
#endif
#ifdef ZTS
@@ -107,7 +107,7 @@ static int php_random_bytes(void *bytes, size_t size)
amount_to_read
*/
- n = getrandom(bytes + read_bytes, amount_to_read, 0);
+ n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0);
if (n == -1) {
if (errno == EINTR || errno == EAGAIN) {
@@ -140,7 +140,13 @@ static int php_random_bytes(void *bytes, size_t size)
return FAILURE;
}
/* Does the file exist and is it a character device? */
- if (fstat(fd, &st) != 0 || !S_ISCHR(st.st_mode)) {
+ if (fstat(fd, &st) != 0 ||
+# ifdef S_IFNAM
+ !(S_IFNAM(st.st_mode) || S_ISCHR(st.st_mode))
+# else
+ !S_ISCHR(st.st_mode)
+# endif
+ ) {
close(fd);
zend_throw_exception(zend_ce_exception, "Error reading from source device", 0);
return FAILURE;