Skip to content

Commit f30f358

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix shm corruption with coercion in options of unserialize()
2 parents aab5045 + ff86c59 commit f30f358

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Shm corruption with coercion in options of unserialize()
3+
--FILE--
4+
<?php
5+
class MyStringable {
6+
public function __toString(): string {
7+
return "0";
8+
}
9+
}
10+
11+
unserialize("{}", ["allowed_classes" => [new MyStringable]]);
12+
?>
13+
--EXPECTF--
14+
Warning: unserialize(): Error at offset 0 of 2 bytes in %s on line %d

ext/standard/var.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,19 +1415,20 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co
14151415
function_name, zend_zval_value_name(entry));
14161416
goto cleanup;
14171417
}
1418-
zend_string *name = zval_try_get_string(entry);
1418+
zend_string *tmp_str;
1419+
zend_string *name = zval_try_get_tmp_string(entry, &tmp_str);
14191420
if (UNEXPECTED(name == NULL)) {
14201421
goto cleanup;
14211422
}
14221423
if (UNEXPECTED(!zend_is_valid_class_name(name))) {
14231424
zend_value_error("%s(): Option \"allowed_classes\" must be an array of class names, \"%s\" given", function_name, ZSTR_VAL(name));
1424-
zend_string_release_ex(name, false);
1425+
zend_tmp_string_release(tmp_str);
14251426
goto cleanup;
14261427
}
14271428
zend_string *lcname = zend_string_tolower(name);
14281429
zend_hash_add_empty_element(class_hash, lcname);
1429-
zend_string_release_ex(name, false);
14301430
zend_string_release_ex(lcname, false);
1431+
zend_tmp_string_release(tmp_str);
14311432
} ZEND_HASH_FOREACH_END();
14321433
}
14331434
php_var_unserialize_set_allowed_classes(var_hash, class_hash);

0 commit comments

Comments
 (0)