Skip to content

Commit 20fe817

Browse files
committed
Fix GH-20771: Assertion failure when getUnicodeHost() returns empty string
If nothing was added to a smart_str, the interned empty string is returned, and therefore ZVAL_NEW_STR is wrong as it'll set the REFCOUNTED flag.
1 parent 0f01a01 commit 20fe817

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20771 (Assertion failure when getUnicodeHost() returns empty string)
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$url = Uri\WhatWg\Url::parse('test://');
9+
10+
var_dump($url->getUnicodeHost());
11+
12+
?>
13+
--EXPECT--
14+
string(0) ""

ext/uri/uri_parser_whatwg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static zend_result php_uri_parser_whatwg_host_read(void *uri, php_uri_component_
365365
lxb_url_serialize_host_unicode(&lexbor_idna, &lexbor_uri->host, serialize_to_smart_str_callback, &host_str);
366366
lxb_unicode_idna_clean(&lexbor_idna);
367367

368-
ZVAL_NEW_STR(retval, smart_str_extract(&host_str));
368+
ZVAL_STR(retval, smart_str_extract(&host_str));
369369
break;
370370
}
371371
case PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII:

0 commit comments

Comments
 (0)