Skip to content

Commit 8389197

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix shm corruption with coercion in options of unserialize()
2 parents ffc548d + 88f8c5c commit 8389197

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
@@ -1414,19 +1414,20 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co
14141414
function_name, zend_zval_value_name(entry));
14151415
goto cleanup;
14161416
}
1417-
zend_string *name = zval_try_get_string(entry);
1417+
zend_string *tmp_str;
1418+
zend_string *name = zval_try_get_tmp_string(entry, &tmp_str);
14181419
if (UNEXPECTED(name == NULL)) {
14191420
goto cleanup;
14201421
}
14211422
if (UNEXPECTED(!zend_is_valid_class_name(name))) {
14221423
zend_value_error("%s(): Option \"allowed_classes\" must be an array of class names, \"%s\" given", function_name, ZSTR_VAL(name));
1423-
zend_string_release_ex(name, false);
1424+
zend_tmp_string_release(tmp_str);
14241425
goto cleanup;
14251426
}
14261427
zend_string *lcname = zend_string_tolower(name);
14271428
zend_hash_add_empty_element(class_hash, lcname);
1428-
zend_string_release_ex(name, false);
14291429
zend_string_release_ex(lcname, false);
1430+
zend_tmp_string_release(tmp_str);
14301431
} ZEND_HASH_FOREACH_END();
14311432
}
14321433
php_var_unserialize_set_allowed_classes(var_hash, class_hash);

0 commit comments

Comments
 (0)