Skip to content

Commit 0f72482

Browse files
Merge branch 'php:master' into master
2 parents f553344 + 2740920 commit 0f72482

File tree

10 files changed

+59
-19
lines changed

10 files changed

+59
-19
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ PHP NEWS
8181
. Added Randomizer::nextFloat(), ::getFloat(), and IntervalBoundary. (timwolla)
8282
. Fix GH-10292 (Made the default value of the first param of srand() and
8383
mt_srand() nullable). (kocsismate)
84+
. Enable getrandom() for NetBSD (from 10.x). (David Carlier)
8485

8586
- Reflection:
8687
. Fix GH-9470 (ReflectionMethod constructor should not find private parent
@@ -101,6 +102,8 @@ PHP NEWS
101102
. Make array_pad's $length warning less confusing. (nielsdos)
102103
. E_WARNING emitted by strtok in the caase both arguments are not provided when
103104
starting tokenisation. (David Carlier)
105+
. password_hash() will now chain the original RandomException to the ValueError
106+
on salt generation failure. (timwolla)
104107

105108
- Streams:
106109
. Fixed bug #51056: blocking fread() will block even if data is available.

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ PHP 8.3 UPGRADE NOTES
6969
can have. Before, it was only possible to add at most 1048576 elements at a
7070
time.
7171
. strtok() raises a warning in the case token is not provided when starting tokenization.
72+
. password_hash() will now chain the underlying Random\RandomException
73+
as the ValueError’s $previous Exception when salt generation fails.
7274

7375
========================================
7476
6. New Functions

ext/posix/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if test "$PHP_POSIX" = "yes"; then
1010

1111
AC_CHECK_HEADERS([sys/mkdev.h sys/sysmacros.h])
1212

13-
AC_CHECK_FUNCS(seteuid setegid setsid getsid getpgid ctermid mkfifo mknod setrlimit getrlimit getgroups makedev initgroups getgrgid_r)
13+
AC_CHECK_FUNCS(seteuid setegid setsid getsid getpgid ctermid mkfifo mknod setrlimit getrlimit getgroups makedev initgroups getgrgid_r posix_pathconf)
1414

1515
AC_MSG_CHECKING([for working ttyname_r() implementation])
1616
AC_RUN_IFELSE([AC_LANG_SOURCE([[

ext/posix/posix.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ PHP_FUNCTION(posix_sysconf)
11971197
RETURN_LONG(sysconf(conf_id));
11981198
}
11991199

1200+
#ifdef HAVE_POSIX_PATHCONF
12001201
PHP_FUNCTION(posix_pathconf)
12011202
{
12021203
zend_long name, ret;
@@ -1257,3 +1258,4 @@ PHP_FUNCTION(posix_fpathconf)
12571258

12581259
RETURN_LONG(ret);
12591260
}
1261+
#endif

ext/posix/posix.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ function posix_initgroups(string $username, int $group_id): bool {}
428428

429429
function posix_sysconf(int $conf_id): int {}
430430

431+
#ifdef HAVE_POSIX_PATHCONF
431432
function posix_pathconf(string $path, int $name): int|false {}
432433
/** @param resource|int $file_descriptor */
433434
function posix_fpathconf($file_descriptor, int $name): int|false {}
435+
#endif

ext/posix/posix_arginfo.h

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/posix/tests/posix_fpathconf.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Test posix_fpathconf
33
--EXTENSIONS--
44
posix
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists("posix_pathconf")) die("skip only platforms with posix_pathconf");
8+
?>
59
--FILE--
610
<?php
711
var_dump(posix_fpathconf(-1, POSIX_PC_PATH_MAX));

ext/posix/tests/posix_pathconf.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Test posix_pathconf
33
--EXTENSIONS--
44
posix
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists("posix_pathconf")) die("skip only platforms with posix_pathconf");
8+
?>
59
--FILE--
610
<?php
711
try {

ext/random/random.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949

5050
#if HAVE_SYS_PARAM_H
5151
# include <sys/param.h>
52-
# if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || defined(__sun)
52+
# if (__FreeBSD__ && __FreeBSD_version > 1200000) || (__DragonFly__ && __DragonFly_version >= 500700) || \
53+
defined(__sun) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000)
5354
# include <sys/random.h>
5455
# endif
5556
#endif
@@ -502,14 +503,27 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
502503
}
503504
return FAILURE;
504505
}
505-
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001) || defined(__APPLE__) || defined(__GLIBC__))
506+
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001 && __NetBSD_Version__ < 1000000000) || \
507+
defined(__APPLE__))
508+
/*
509+
* OpenBSD until there is a valid equivalent
510+
* or NetBSD before the 10.x release
511+
* falls back to arc4random_buf
512+
* giving a decent output, the main benefit
513+
* is being (relatively) failsafe.
514+
* Older macOs releases fall also into this
515+
* category for reasons explained above.
516+
*/
506517
arc4random_buf(bytes, size);
507518
#else
508519
size_t read_bytes = 0;
509520
ssize_t n;
510-
# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || defined(__sun)
511-
/* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD getrandom(2) function*/
512-
/* Keep reading until we get enough entropy */
521+
# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || \
522+
defined(__sun) || (defined(__NetBSD__) && __NetBSD_Version__ >= 1000000000)
523+
/* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD/NetBSD getrandom(2) function
524+
* Being a syscall, implemented in the kernel, getrandom offers higher quality output
525+
* compared to the arc4random api albeit a fallback to /dev/urandom is considered.
526+
*/
513527
while (read_bytes < size) {
514528
errno = 0;
515529

@@ -594,20 +608,17 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
594608
for (read_bytes = 0; read_bytes < size; read_bytes += (size_t) n) {
595609
errno = 0;
596610
n = read(fd, bytes + read_bytes, size - read_bytes);
597-
if (n <= 0) {
598-
break;
599-
}
600-
}
601611

602-
if (read_bytes < size) {
603-
if (should_throw) {
604-
if (errno != 0) {
605-
zend_throw_exception_ex(random_ce_Random_RandomException, 0, "Could not gather sufficient random data: %s", strerror(errno));
606-
} else {
607-
zend_throw_exception_ex(random_ce_Random_RandomException, 0, "Could not gather sufficient random data");
612+
if (n <= 0) {
613+
if (should_throw) {
614+
if (errno != 0) {
615+
zend_throw_exception_ex(random_ce_Random_RandomException, 0, "Could not gather sufficient random data: %s", strerror(errno));
616+
} else {
617+
zend_throw_exception_ex(random_ce_Random_RandomException, 0, "Could not gather sufficient random data");
618+
}
608619
}
620+
return FAILURE;
609621
}
610-
return FAILURE;
611622
}
612623
}
613624
#endif

ext/standard/password.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static zend_string* php_password_make_salt(size_t length) /* {{{ */
8383
}
8484

8585
buffer = zend_string_alloc(length * 3 / 4 + 1, 0);
86-
if (FAILURE == php_random_bytes_silent(ZSTR_VAL(buffer), ZSTR_LEN(buffer))) {
86+
if (FAILURE == php_random_bytes_throw(ZSTR_VAL(buffer), ZSTR_LEN(buffer))) {
8787
zend_value_error("Unable to generate salt");
8888
zend_string_release_ex(buffer, 0);
8989
return NULL;

0 commit comments

Comments
 (0)