Skip to content

Commit a333d79

Browse files
committed
General fix
1 parent 6007c09 commit a333d79

3 files changed

Lines changed: 38 additions & 14 deletions

File tree

ext/standard/tests/serialize/serialization_objects_009.phpt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ Custom unserialization of classes with no custom unserializer.
33
--FILE--
44
<?php
55
$ser = 'C:1:"C":6:{dasdas}';
6-
$a = unserialize($ser);
6+
7+
try {
8+
unserialize($ser);
9+
} catch (Throwable $e) {
10+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
11+
}
12+
713
eval('class C {}');
8-
$b = unserialize($ser);
914

10-
var_dump($a, $b);
15+
try {
16+
unserialize($ser);
17+
} catch (Throwable $e) {
18+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
19+
}
1120

1221
echo "Done";
1322
?>
14-
--EXPECTF--
15-
Warning: Class __PHP_Incomplete_Class has no unserializer in %sserialization_objects_009.php on line %d
16-
17-
Warning: Class C has no unserializer in %sserialization_objects_009.php on line %d
18-
object(__PHP_Incomplete_Class)#%d (1) {
19-
["__PHP_Incomplete_Class_Name"]=>
20-
string(1) "C"
21-
}
22-
object(C)#%d (0) {
23-
}
23+
--EXPECT--
24+
Exception: Class __PHP_Incomplete_Class has no unserializer
25+
Exception: Class C has no unserializer
2426
Done

ext/standard/var_unserializer.re

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
771771
}
772772

773773
if (ce->unserialize == NULL) {
774-
zend_error(E_WARNING, "Class %s has no unserializer", ZSTR_VAL(ce->name));
774+
zend_throw_exception_ex(NULL, 0, "Class %s has no unserializer", ZSTR_VAL(ce->name));
775775
object_init_ex(rval, ce);
776776
} else if (ce->unserialize(rval, ce, (const unsigned char*)*p, datalen, (zend_unserialize_data *)var_hash) != SUCCESS) {
777777
return 0;

ext/uri/tests/gh22046.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-22046: The unserialize function with Uri\WhatWg\Url leads to NULL pointer dereference when object serialized back
3+
--FILE--
4+
<?php
5+
6+
$payload = 'C:14:"Uri\WhatWg\Url":0:{}';
7+
try {
8+
unserialize($payload);
9+
} catch (Throwable $e) {
10+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
11+
}
12+
13+
$payload = 'C:15:"Uri\Rfc3986\Uri":0:{}';
14+
try {
15+
unserialize($payload);
16+
} catch (Throwable $e) {
17+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
18+
}
19+
?>
20+
--EXPECT--
21+
Exception: Class Uri\WhatWg\Url has no unserializer
22+
Exception: Class Uri\Rfc3986\Uri has no unserializer

0 commit comments

Comments
 (0)