Skip to content

Commit d58ecb5

Browse files
authored
uri: Clean up logic in uri_unserialize() (#19903)
* uri: Check early whether we would be overwriting an existing URI in `uri_unserialize()` * uri: Access the CE consistently in `uri_unserialize()`
1 parent 5897071 commit d58ecb5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ext/uri/php_uri.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,13 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS)
823823
ZEND_PARSE_PARAMETERS_END();
824824

825825
zend_object *object = Z_OBJ_P(ZEND_THIS);
826+
uri_internal_t *internal_uri = uri_internal_from_obj(object);
827+
if (internal_uri->uri != NULL) {
828+
/* Intentionally throw two exceptions for proper chaining. */
829+
zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(object->ce->name));
830+
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name));
831+
RETURN_THROWS();
832+
}
826833

827834
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
828835
if (zend_hash_num_elements(data) != 2) {
@@ -849,13 +856,6 @@ static void uri_unserialize(INTERNAL_FUNCTION_PARAMETERS)
849856
RETURN_THROWS();
850857
}
851858

852-
uri_internal_t *internal_uri = uri_internal_from_obj(object);
853-
if (internal_uri->uri != NULL) {
854-
/* Intentionally throw two exceptions for proper chaining. */
855-
zend_throw_error(NULL, "Cannot modify readonly object of class %s", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name));
856-
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name));
857-
RETURN_THROWS();
858-
}
859859
internal_uri->uri = internal_uri->parser->parse(Z_STRVAL_P(uri_zv), Z_STRLEN_P(uri_zv), NULL, NULL, true);
860860
if (internal_uri->uri == NULL) {
861861
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(object->ce->name));

0 commit comments

Comments
 (0)