Skip to content

Commit 88f8c5c

Browse files
committed
Fix shm corruption with coercion in options of unserialize()
Closes phpGH-20129.
1 parent 5a7c84f commit 88f8c5c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ PHP NEWS
4141
. Partially fixed bug GH-16317 (SimpleXML does not allow __debugInfo() overrides
4242
to work). (nielsdos)
4343

44+
- Standard:
45+
. Fix shm corruption with coercion in options of unserialize(). (nielsdos)
46+
4447
- XMLReader:
4548
. Fix arginfo/zpp violations when LIBXML_SCHEMAS_ENABLED is not available.
4649
(nielsdos)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Shm corruption with coercion in options of unserialize()
3+
--FILE--
4+
<?php
5+
unserialize("{}", ["allowed_classes" => [0]]);
6+
?>
7+
--EXPECTF--
8+
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
@@ -1366,13 +1366,14 @@ PHPAPI void php_unserialize_with_options(zval *return_value, const char *buf, co
13661366
}
13671367
if(class_hash && Z_TYPE_P(classes) == IS_ARRAY) {
13681368
zval *entry;
1369-
zend_string *lcname;
1369+
zend_string *lcname, *tmp_str, *str;
13701370

13711371
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(classes), entry) {
1372-
convert_to_string(entry);
1373-
lcname = zend_string_tolower(Z_STR_P(entry));
1372+
str = zval_get_tmp_string(entry, &tmp_str);
1373+
lcname = zend_string_tolower(str);
13741374
zend_hash_add_empty_element(class_hash, lcname);
13751375
zend_string_release_ex(lcname, 0);
1376+
zend_tmp_string_release(tmp_str);
13761377
} ZEND_HASH_FOREACH_END();
13771378

13781379
/* Exception during string conversion. */

0 commit comments

Comments
 (0)