Skip to content

Commit 9b88d13

Browse files
committed
Review fixes
1 parent 0f5d94a commit 9b88d13

File tree

6 files changed

+24
-3
lines changed

6 files changed

+24
-3
lines changed

ext/filter/logical_filters.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
+----------------------------------------------------------------------+
1717
*/
1818

19+
#include "zend_exceptions.h"
1920
#include "php_filter.h"
2021
#include "filter_private.h"
21-
#include "ext/standard/url.h"
2222
#include "ext/pcre/php_pcre.h"
2323
#include "ext/uri/php_uri.h"
2424

@@ -610,7 +610,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
610610

611611
uri_handler_t *uri_handler = php_uri_get_handler(parser_name_set ? parser_name : NULL);
612612
if (uri_handler == NULL) {
613-
zend_throw_error(NULL, "Invalid URI parser used");
613+
zend_value_error("%s(): \"uri_parser_class\" option has invalid value", get_active_function_name());
614614
RETURN_VALIDATION_FAILED
615615
}
616616

ext/openssl/xp_ssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ext/uri/php_uri.h"
2727
#include "streams/php_streams_int.h"
2828
#include "zend_smart_str.h"
29+
#include "zend_exceptions.h"
2930
#include "php_openssl.h"
3031
#include "php_network.h"
3132
#include <openssl/ssl.h>
@@ -2628,6 +2629,7 @@ static char *php_openssl_get_url_name(const char *resourcename,
26282629

26292630
uri_handler_t *uri_handler = php_stream_context_get_uri_handler("ssl", context);
26302631
if (uri_handler == NULL) {
2632+
zend_value_error("%s(): Provided stream context has invalid value for the \"uri_parser_class\" option", get_active_function_name());
26312633
return NULL;
26322634
}
26332635

ext/standard/ftp_fopen_wrapper.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "php_globals.h"
2222
#include "php_network.h"
2323
#include "php_ini.h"
24+
#include "zend_exceptions.h"
2425

2526
#include <stdio.h>
2627
#include <stdlib.h>
@@ -136,6 +137,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char
136137

137138
uri_handler_t *uri_handler = php_stream_context_get_uri_handler("ftp", context);
138139
if (uri_handler == NULL) {
140+
zend_value_error("%s(): Provided stream context has invalid value for the \"uri_parser_class\" option", get_active_function_name());
139141
return NULL;
140142
}
141143

@@ -956,6 +958,7 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr
956958

957959
uri_handler_t *uri_handler = php_stream_context_get_uri_handler("ftp", context);
958960
if (uri_handler == NULL) {
961+
zend_value_error("%s(): Provided stream context has invalid value for the \"uri_parser_class\" option", get_active_function_name());
959962
return 0;
960963
}
961964

@@ -1022,6 +1025,7 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr
10221025
return 1;
10231026

10241027
rename_errexit:
1028+
php_uri_struct_free(resource_from);
10251029
if (resource_to) {
10261030
php_uri_struct_free(resource_to);
10271031
}

ext/standard/http_fopen_wrapper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "php_ini.h"
2727
#include "ext/standard/basic_functions.h"
2828
#include "zend_smart_str.h"
29+
#include "zend_exceptions.h"
2930

3031
#include <stdio.h>
3132
#include <stdlib.h>
@@ -394,6 +395,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
394395

395396
uri_handler_t *uri_handler = php_stream_context_get_uri_handler("http", context);
396397
if (uri_handler == NULL) {
398+
zend_value_error("%s(): Provided stream context has invalid value for the \"uri_parser_class\" option", get_active_function_name());
397399
return NULL;
398400
}
399401
resource = php_uri_parse_to_struct(uri_handler, path, strlen(path), URI_COMPONENT_READ_RAW, true);

ext/standard/tests/file/file_get_contents_with_custom_uri_parser.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ Test file_get_contents() function when a custom URI parser is configured
33
--FILE--
44
<?php
55

6+
try {
7+
$context = stream_context_create([
8+
"http" => [
9+
"uri_parser_class" => "not-exists",
10+
],
11+
]);
12+
var_dump(file_get_contents("https://example.com", context: $context));
13+
} catch (Error $e) {
14+
echo $e->getMessage() . "\n";
15+
}
16+
617
$context = stream_context_create([
718
"http" => [
819
"uri_parser_class" => null,
@@ -26,6 +37,8 @@ var_dump(file_get_contents("https://exa%23mple.org", context: $context)); // inv
2637

2738
?>
2839
--EXPECTF--
40+
file_get_contents(): Provided stream context has invalid value for the "uri_parser_class" option
41+
2942
Warning: file_get_contents(https:///example.com): Failed to open stream: operation failed in %s on line %d
3043
bool(false)
3144

main/streams/streams.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,7 @@ PHPAPI struct uri_handler_t *php_stream_context_get_uri_handler(const char *wrap
24682468
}
24692469

24702470
zval *uri_handler_name = php_stream_context_get_option(context, wrappername, "uri_parser_class");
2471-
if (uri_handler_name == NULL) {
2471+
if (uri_handler_name == NULL || Z_TYPE_P(uri_handler_name) == IS_NULL) {
24722472
return php_uri_get_handler(NULL);
24732473
}
24742474

0 commit comments

Comments
 (0)