Skip to content

Commit dd5c5ca

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Handle exceptions from __toString in XXH3's initialization Fix phpdbg segmentation fault in case of malformed input
2 parents a6a20c9 + 7463e70 commit dd5c5ca

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ PHP NEWS
2323
. Fixed bug #67244 (Wrong owner:group for listening unix socket).
2424
(Jakub Zelenka)
2525

26+
- Hash:
27+
. Handle exceptions from __toString in XXH3's initialization (nielsdos)
28+
2629
- LDAP:
2730
. Fixed bug GH-10112 (LDAP\Connection::__construct() refers to ldap_create()).
2831
(cmb)
@@ -40,6 +43,7 @@ PHP NEWS
4043
. Fix undefined behaviour in phpdbg_load_module_or_extension(). (nielsdos)
4144
. Fix NULL pointer dereference in phpdbg_create_conditional_breal(). (nielsdos)
4245
. Fix GH-9710: phpdbg memory leaks by option "-h" (nielsdos)
46+
. Fix phpdbg segmentation fault in case of malformed input (nielsdos)
4347

4448
- Posix:
4549
. Fix memory leak in posix_ttyname() (girgias)

ext/hash/hash_xxhash.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ zend_always_inline static void _PHP_XXH3_Init(PHP_XXH3_64_CTX *ctx, HashTable *a
174174
func_init_seed(&ctx->s, (XXH64_hash_t)Z_LVAL_P(_seed));
175175
return;
176176
} else if (_secret) {
177-
convert_to_string(_secret);
177+
if (!try_convert_to_string(_secret)) {
178+
return;
179+
}
178180
size_t len = Z_STRLEN_P(_secret);
179181
if (len < PHP_XXH3_SECRET_SIZE_MIN) {
180182
zend_throw_error(NULL, "%s: Secret length must be >= %u bytes, %zu bytes passed", algo_name, XXH3_SECRET_SIZE_MIN, len);

ext/hash/tests/xxhash_secret.phpt

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Hash: xxHash secret
33
--FILE--
44
<?php
55

6+
class StringableThrowingClass {
7+
public function __toString(): string {
8+
throw new Exception('exception in __toString');
9+
return '';
10+
}
11+
}
12+
613
foreach (["xxh3", "xxh128"] as $a) {
714

815
//$secret = random_bytes(256);
@@ -14,6 +21,12 @@ foreach (["xxh3", "xxh128"] as $a) {
1421
var_dump($e->getMessage());
1522
}
1623

24+
try {
25+
$ctx = hash_init($a, options: ["secret" => new StringableThrowingClass()]);
26+
} catch (Throwable $e) {
27+
var_dump($e->getMessage());
28+
}
29+
1730
try {
1831
$ctx = hash_init($a, options: ["secret" => str_repeat('a', 17)]);
1932
} catch (Throwable $e) {
@@ -35,8 +48,10 @@ foreach (["xxh3", "xxh128"] as $a) {
3548
?>
3649
--EXPECT--
3750
string(67) "xxh3: Only one of seed or secret is to be passed for initialization"
51+
string(23) "exception in __toString"
3852
string(57) "xxh3: Secret length must be >= 136 bytes, 17 bytes passed"
3953
8028aa834c03557a == 8028aa834c03557a == true
4054
string(69) "xxh128: Only one of seed or secret is to be passed for initialization"
55+
string(23) "exception in __toString"
4156
string(59) "xxh128: Secret length must be >= 136 bytes, 17 bytes passed"
4257
54279097795e7218093a05d4d781cbb9 == 54279097795e7218093a05d4d781cbb9 == true

sapi/phpdbg/phpdbg_utils.c

+3
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable
466466
case ']':
467467
break;
468468
case '>':
469+
if (!last_index) {
470+
goto error;
471+
}
469472
if (last_index[index_len - 1] == '-') {
470473
new_index = 1;
471474
index_len--;

sapi/phpdbg/tests/watch_007.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test malformed watchpoint name
3+
--INI--
4+
opcache.optimization_level=0
5+
--PHPDBG--
6+
b test
7+
r
8+
w $>
9+
q
10+
--EXPECTF--
11+
[Successful compilation of %s]
12+
prompt> [Breakpoint #0 added at test]
13+
prompt> [Breakpoint #0 in test() at %s:%d, hits: 1]
14+
>00004: }
15+
00005: test();
16+
00006: $a = 2;
17+
prompt> [Malformed input]
18+
prompt>
19+
--FILE--
20+
<?php
21+
$a = 1;
22+
function test() {
23+
}
24+
test();
25+
$a = 2;

0 commit comments

Comments
 (0)