Skip to content

Commit fff8c11

Browse files
committed
Merge remote-tracking branch 'upstream/master' into upstream_rfc/scoped_rng_for_pr
2 parents 87dcae4 + d6fc165 commit fff8c11

File tree

8 files changed

+88
-1
lines changed

8 files changed

+88
-1
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
. Reduced the memory footprint of strings returned by var_export(),
1212
json_encode(), serialize(), iconv_*(), mb_ereg*(), session_create_id(),
1313
http_build_query(), strstr(), Reflection*::__toString(). (Arnaud)
14+
. Fixed bug GH-8995 (WeakMap object reference offset causing TypeError).
15+
(Tobias Bachert)
1416

1517
- COM:
1618
. Fixed bug GH-8750 (Can not create VT_ERROR variant type). (cmb)
@@ -30,6 +32,9 @@ PHP NEWS
3032
. Fixed empty array returned by str_split on empty input. (Michael Vorisek)
3133
. Added ini_parse_quantity function to convert ini quantities shorthand
3234
notation to int. (Dennis Snell)
35+
. Enable arc4random_buf for Linux glibc 2.36 and onwards
36+
for the random_bytes. (Cristian Rodriguez)
37+
. Uses CCRandomGenerateBytes instead of arc4random_buf on macOs. (David Carlier).
3338

3439
07 Jul 2022, PHP 8.2.0alpha3
3540

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
WeakMap object reference offset
3+
--FILE--
4+
<?php
5+
6+
$map = new WeakMap;
7+
$obj = new stdClass;
8+
$obj2 = &$obj;
9+
10+
$map[$obj] = 1;
11+
var_dump(count($map));
12+
var_dump($map);
13+
var_dump(isset($map[$obj]));
14+
var_dump(!empty($map[$obj]));
15+
var_dump($map[$obj]);
16+
17+
?>
18+
--EXPECT--
19+
int(1)
20+
object(WeakMap)#1 (1) {
21+
[0]=>
22+
array(2) {
23+
["key"]=>
24+
object(stdClass)#2 (0) {
25+
}
26+
["value"]=>
27+
int(1)
28+
}
29+
}
30+
bool(true)
31+
bool(true)
32+
int(1)

Zend/zend_weakrefs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ static zval *zend_weakmap_read_dimension(zend_object *object, zval *offset, int
332332
return NULL;
333333
}
334334

335+
ZVAL_DEREF(offset);
335336
if (Z_TYPE_P(offset) != IS_OBJECT) {
336337
zend_type_error("WeakMap key must be an object");
337338
return NULL;
@@ -362,6 +363,7 @@ static void zend_weakmap_write_dimension(zend_object *object, zval *offset, zval
362363
return;
363364
}
364365

366+
ZVAL_DEREF(offset);
365367
if (Z_TYPE_P(offset) != IS_OBJECT) {
366368
zend_type_error("WeakMap key must be an object");
367369
return;
@@ -390,6 +392,7 @@ static void zend_weakmap_write_dimension(zend_object *object, zval *offset, zval
390392
/* int return and check_empty due to Object Handler API */
391393
static int zend_weakmap_has_dimension(zend_object *object, zval *offset, int check_empty)
392394
{
395+
ZVAL_DEREF(offset);
393396
if (Z_TYPE_P(offset) != IS_OBJECT) {
394397
zend_type_error("WeakMap key must be an object");
395398
return 0;
@@ -409,6 +412,7 @@ static int zend_weakmap_has_dimension(zend_object *object, zval *offset, int che
409412

410413
static void zend_weakmap_unset_dimension(zend_object *object, zval *offset)
411414
{
415+
ZVAL_DEREF(offset);
412416
if (Z_TYPE_P(offset) != IS_OBJECT) {
413417
zend_type_error("WeakMap key must be an object");
414418
return;

ext/mbstring/mbstring.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,6 @@ PHP_FUNCTION(mb_http_input)
12971297
entry = MBSTRG(http_input_list);
12981298
n = MBSTRG(http_input_list_size);
12991299
if (n == 0) {
1300-
// TODO should return empty string?
13011300
RETURN_FALSE;
13021301
}
13031302
// TODO Use smart_str instead.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
mb_http_input() - Returns FALSE for $type 'L' or 'l'
3+
--EXTENSIONS--
4+
mbstring
5+
--INI--
6+
input_encoding=-1
7+
--FILE--
8+
<?php
9+
var_dump(mb_http_input('L'));
10+
var_dump(mb_http_input('l'));
11+
?>
12+
--EXPECT--
13+
Warning: PHP Startup: INI setting contains invalid encoding "-1" in Unknown on line 0
14+
15+
Warning: PHP Startup: INI setting contains invalid encoding "-1" in Unknown on line 0
16+
bool(false)
17+
bool(false)

ext/random/config.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ dnl Check for arc4random on BSD systems
33
dnl
44
AC_CHECK_DECLS([arc4random_buf])
55

6+
dnl
7+
dnl Check for CCRandomGenerateBytes
8+
dnl header absent in previous macOs releases
9+
dnl
10+
AC_CHECK_HEADERS([CommonCrypto/CommonRandom.h])
11+
612
dnl
713
dnl Setup extension
814
dnl

ext/random/random.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
# endif
5555
#endif
5656

57+
#if HAVE_COMMONCRYPTO_COMMONRANDOM_H
58+
# include <CommonCrypto/CommonCryptoError.h>
59+
# include <CommonCrypto/CommonRandom.h>
60+
#endif
61+
5762
#if __has_feature(memory_sanitizer)
5863
# include <sanitizer/msan_interface.h>
5964
#endif
@@ -481,6 +486,19 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw)
481486
}
482487
return FAILURE;
483488
}
489+
#elif HAVE_COMMONCRYPTO_COMMONRANDOM_H
490+
/*
491+
* Purposely prioritized upon arc4random_buf for modern macOs releases
492+
* arc4random api on this platform uses `ccrng_generate` which returns
493+
* a status but silented to respect the "no fail" arc4random api interface
494+
* the vast majority of the time, it works fine ; but better make sure we catch failures
495+
*/
496+
if (CCRandomGenerateBytes(bytes, size) != kCCSuccess) {
497+
if (should_throw) {
498+
zend_throw_exception(zend_ce_exception, "Error generating bytes", 0);
499+
}
500+
return FAILURE;
501+
}
484502
#elif HAVE_DECL_ARC4RANDOM_BUF && ((defined(__OpenBSD__) && OpenBSD >= 201405) || (defined(__NetBSD__) && __NetBSD_Version__ >= 700000001) || defined(__APPLE__))
485503
arc4random_buf(bytes, size);
486504
#else

ext/standard/config.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ dnl Check for arc4random on BSD systems
403403
dnl
404404
AC_CHECK_DECLS([arc4random_buf])
405405

406+
dnl
407+
dnl Check for CCRandomGenerateBytes
408+
dnl header absent in previous macOs releases
409+
dnl
410+
AC_CHECK_HEADERS([CommonCrypto/CommonRandom.h])
411+
406412
dnl
407413
dnl Check for argon2
408414
dnl

0 commit comments

Comments
 (0)