Skip to content

Commit afb7b97

Browse files
authored
Fixes to uri serialization (php#20369)
- Incoming data should never have an INDIRECT element, that would be a violation of the rules wrt the INDIRECT types. Therefore there was never a need to use the _ind variant of the hash table find. - It doesn't matter now because there are no properties; but the get_properties handler cannot be used in the output of a __serialize call as that would expose INDIRECT elements. To prevent issues in the future, make it an empty array as a placeholder. If in the future properties are added, then this will hard fail instead of silently fail with INDIRECTs.
1 parent 51ca716 commit afb7b97

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

ext/uri/php_uri.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize)
800800
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
801801

802802
/* Serialize regular properties: second array */
803-
ZVAL_ARR(&arr, uri_object->std.handlers->get_properties(&uri_object->std));
804-
Z_TRY_ADDREF(arr);
803+
ZVAL_EMPTY_ARRAY(&arr);
805804
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
806805
}
807806

@@ -840,7 +839,7 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS)
840839
RETURN_THROWS();
841840
}
842841

843-
zval *uri_zv = zend_hash_str_find_ind(Z_ARRVAL_P(arr), ZEND_STRL(PHP_URI_SERIALIZE_URI_FIELD_NAME));
842+
zval *uri_zv = zend_hash_str_find(Z_ARRVAL_P(arr), ZEND_STRL(PHP_URI_SERIALIZE_URI_FIELD_NAME));
844843
if (uri_zv == NULL || Z_TYPE_P(uri_zv) != IS_STRING) {
845844
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(uri_object->std.ce->name));
846845
RETURN_THROWS();
@@ -990,8 +989,7 @@ PHP_METHOD(Uri_WhatWg_Url, __serialize)
990989
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
991990

992991
/* Serialize regular properties: second array */
993-
ZVAL_ARR(&arr, this_object->std.handlers->get_properties(&this_object->std));
994-
Z_ADDREF(arr);
992+
ZVAL_EMPTY_ARRAY(&arr);
995993
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &arr);
996994
}
997995

0 commit comments

Comments
 (0)