Skip to content

Commit a4e5c2d

Browse files
committed
General fix
1 parent 123cc27 commit a4e5c2d

4 files changed

Lines changed: 18 additions & 26 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
@@ -769,7 +769,7 @@ static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
769769
}
770770

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

ext/uri/php_uri.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,13 +1094,6 @@ PHPAPI zend_object *php_uri_object_handler_clone(zend_object *object)
10941094
return &new_uri_object->std;
10951095
}
10961096

1097-
PHPAPI int php_uri_object_handler_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buf, size_t buf_len, zend_unserialize_data *data)
1098-
{
1099-
zend_throw_exception_ex(NULL, 0, "Unserialization of %s using the \"C\" format is unsupported", ZSTR_VAL(ce->name));
1100-
1101-
return FAILURE;
1102-
}
1103-
11041097
PHPAPI zend_result php_uri_parser_register(const php_uri_parser *uri_parser)
11051098
{
11061099
zend_string *key = zend_string_init_interned(uri_parser->name, strlen(uri_parser->name), true);
@@ -1123,7 +1116,6 @@ static PHP_MINIT_FUNCTION(uri)
11231116
php_uri_ce_rfc3986_uri = register_class_Uri_Rfc3986_Uri();
11241117
php_uri_ce_rfc3986_uri->create_object = php_uri_object_create_rfc3986;
11251118
php_uri_ce_rfc3986_uri->default_object_handlers = &object_handlers_rfc3986_uri;
1126-
php_uri_ce_rfc3986_uri->unserialize = &php_uri_object_handler_unserialize;
11271119
memcpy(&object_handlers_rfc3986_uri, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
11281120
object_handlers_rfc3986_uri.offset = offsetof(php_uri_object, std);
11291121
object_handlers_rfc3986_uri.free_obj = php_uri_object_handler_free;
@@ -1135,7 +1127,6 @@ static PHP_MINIT_FUNCTION(uri)
11351127
php_uri_ce_whatwg_url = register_class_Uri_WhatWg_Url();
11361128
php_uri_ce_whatwg_url->create_object = php_uri_object_create_whatwg;
11371129
php_uri_ce_whatwg_url->default_object_handlers = &object_handlers_whatwg_uri;
1138-
php_uri_ce_whatwg_url->unserialize = &php_uri_object_handler_unserialize;
11391130
memcpy(&object_handlers_whatwg_uri, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
11401131
object_handlers_whatwg_uri.offset = offsetof(php_uri_object, std);
11411132
object_handlers_whatwg_uri.free_obj = php_uri_object_handler_free;
@@ -1145,7 +1136,6 @@ static PHP_MINIT_FUNCTION(uri)
11451136
php_uri_ce_exception = register_class_Uri_UriException(zend_ce_exception);
11461137
php_uri_ce_error = register_class_Uri_UriError(zend_ce_error);
11471138
php_uri_ce_invalid_uri_exception = register_class_Uri_InvalidUriException(php_uri_ce_exception);
1148-
php_uri_ce_invalid_uri_exception->unserialize = &php_uri_object_handler_unserialize;
11491139
php_uri_ce_whatwg_invalid_url_exception = register_class_Uri_WhatWg_InvalidUrlException(php_uri_ce_invalid_uri_exception);
11501140
php_uri_ce_whatwg_url_host_type = register_class_Uri_WhatWg_UrlHostType();
11511141
php_uri_ce_whatwg_url_validation_error = register_class_Uri_WhatWg_UrlValidationError();

ext/uri/tests/gh22046.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ try {
1818
}
1919
?>
2020
--EXPECT--
21-
Exception: Unserialization of Uri\WhatWg\Url using the "C" format is unsupported
22-
Exception: Unserialization of Uri\Rfc3986\Uri using the "C" format is unsupported
21+
Exception: Class Uri\WhatWg\Url has no unserializer
22+
Exception: Class Uri\Rfc3986\Uri has no unserializer

0 commit comments

Comments
 (0)