Skip to content

Commit 88bf489

Browse files
committed
uri: Make the .free_uri handlers safe to call with NULL
The `php_uri_free()` function already unconditionally called `->free_uri()` and thus couldn't be safely used when the `->uri` was `NULL` for some reason. The lexbor implementation was already safe, because `lxb_url_destroy()` is guaranteed to be a noop for `NULL`.
1 parent b27d919 commit 88bf489

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ext/uri/uri_parser_php_parse_url.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ static void uri_parser_php_parse_url_free(void *uri)
158158
{
159159
php_url *parse_url_uri = uri;
160160

161+
if (UNEXPECTED(parse_url_uri == NULL)) {
162+
return;
163+
}
164+
161165
php_url_free(parse_url_uri);
162166
}
163167

ext/uri/uri_parser_rfc3986.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,14 @@ ZEND_ATTRIBUTE_NONNULL static zend_string *php_uri_parser_rfc3986_to_string(void
384384
return uri_string;
385385
}
386386

387-
ZEND_ATTRIBUTE_NONNULL static void php_uri_parser_rfc3986_free(void *uri)
387+
static void php_uri_parser_rfc3986_free(void *uri)
388388
{
389389
php_uri_parser_rfc3986_uris *uriparser_uris = uri;
390390

391+
if (UNEXPECTED(uriparser_uris == NULL)) {
392+
return;
393+
}
394+
391395
uriFreeUriMembersMmA(&uriparser_uris->uri, mm);
392396
uriFreeUriMembersMmA(&uriparser_uris->normalized_uri, mm);
393397

0 commit comments

Comments
 (0)