Skip to content

Commit 5c3bf2b

Browse files
committed
streams: no need to gate php_stream_wrapper_warn calls with options & REPORT_ERRORS
As the underlying function already checks this
1 parent 9658dfc commit 5c3bf2b

4 files changed

Lines changed: 44 additions & 79 deletions

File tree

ext/standard/ftp_fopen_wrapper.c

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -915,18 +915,14 @@ static int php_stream_ftp_unlink(php_stream_wrapper *wrapper, const char *url, i
915915

916916
stream = php_ftp_fopen_connect(wrapper, url, "r", 0, NULL, context, NULL, &resource, NULL, NULL);
917917
if (!stream) {
918-
if (options & REPORT_ERRORS) {
919-
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
920-
"Unable to connect to %s", url);
921-
}
918+
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
919+
"Unable to connect to %s", url);
922920
goto unlink_errexit;
923921
}
924922

925923
if (resource->path == NULL) {
926-
if (options & REPORT_ERRORS) {
927-
php_stream_wrapper_warn(wrapper, context, options, InvalidPath,
928-
"Invalid path provided in %s", url);
929-
}
924+
php_stream_wrapper_warn(wrapper, context, options, InvalidPath,
925+
"Invalid path provided in %s", url);
930926
goto unlink_errexit;
931927
}
932928

@@ -935,10 +931,8 @@ static int php_stream_ftp_unlink(php_stream_wrapper *wrapper, const char *url, i
935931

936932
result = GET_FTP_RESULT(stream);
937933
if (result < 200 || result > 299) {
938-
if (options & REPORT_ERRORS) {
939-
php_stream_wrapper_warn(wrapper, context, options, UnlinkFailed,
940-
"Error Deleting file: %s", tmp_line);
941-
}
934+
php_stream_wrapper_warn(wrapper, context, options, UnlinkFailed,
935+
"Error Deleting file: %s", tmp_line);
942936
goto unlink_errexit;
943937
}
944938

@@ -1000,10 +994,8 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr
1000994

1001995
stream = php_ftp_fopen_connect(wrapper, url_from, "r", 0, NULL, context, NULL, NULL, NULL, NULL);
1002996
if (!stream) {
1003-
if (options & REPORT_ERRORS) {
1004-
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
1005-
"Unable to connect to %s", ZSTR_VAL(resource_from->host));
1006-
}
997+
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
998+
"Unable to connect to %s", ZSTR_VAL(resource_from->host));
1007999
goto rename_errexit;
10081000
}
10091001

@@ -1012,10 +1004,8 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr
10121004

10131005
result = GET_FTP_RESULT(stream);
10141006
if (result < 300 || result > 399) {
1015-
if (options & REPORT_ERRORS) {
1016-
php_stream_wrapper_warn(wrapper, context, options, RenameFailed,
1017-
"Error Renaming file: %s", tmp_line);
1018-
}
1007+
php_stream_wrapper_warn(wrapper, context, options, RenameFailed,
1008+
"Error Renaming file: %s", tmp_line);
10191009
goto rename_errexit;
10201010
}
10211011

@@ -1024,10 +1014,8 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr
10241014

10251015
result = GET_FTP_RESULT(stream);
10261016
if (result < 200 || result > 299) {
1027-
if (options & REPORT_ERRORS) {
1028-
php_stream_wrapper_warn(wrapper, context, options, RenameFailed,
1029-
"Error Renaming file: %s", tmp_line);
1030-
}
1017+
php_stream_wrapper_warn(wrapper, context, options, RenameFailed,
1018+
"Error Renaming file: %s", tmp_line);
10311019
goto rename_errexit;
10321020
}
10331021

@@ -1058,18 +1046,14 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char *url, in
10581046

10591047
stream = php_ftp_fopen_connect(wrapper, url, "r", 0, NULL, context, NULL, &resource, NULL, NULL);
10601048
if (!stream) {
1061-
if (options & REPORT_ERRORS) {
1062-
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
1063-
"Unable to connect to %s", url);
1064-
}
1049+
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
1050+
"Unable to connect to %s", url);
10651051
goto mkdir_errexit;
10661052
}
10671053

10681054
if (resource->path == NULL) {
1069-
if (options & REPORT_ERRORS) {
1070-
php_stream_wrapper_warn(wrapper, context, options, InvalidPath,
1071-
"Invalid path provided in %s", url);
1072-
}
1055+
php_stream_wrapper_warn(wrapper, context, options, InvalidPath,
1056+
"Invalid path provided in %s", url);
10731057
goto mkdir_errexit;
10741058
}
10751059

@@ -1108,10 +1092,8 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char *url, in
11081092
php_stream_printf(stream, "MKD %s\r\n", buf);
11091093
result = GET_FTP_RESULT(stream);
11101094
if (result < 200 || result > 299) {
1111-
if (options & REPORT_ERRORS) {
1112-
php_stream_wrapper_warn(wrapper, context, options, MkdirFailed,
1113-
"%s", tmp_line);
1114-
}
1095+
php_stream_wrapper_warn(wrapper, context, options, MkdirFailed,
1096+
"%s", tmp_line);
11151097
break;
11161098
}
11171099
}
@@ -1153,29 +1135,23 @@ static int php_stream_ftp_rmdir(php_stream_wrapper *wrapper, const char *url, in
11531135

11541136
stream = php_ftp_fopen_connect(wrapper, url, "r", 0, NULL, context, NULL, &resource, NULL, NULL);
11551137
if (!stream) {
1156-
if (options & REPORT_ERRORS) {
1157-
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
1158-
"Unable to connect to %s", url);
1159-
}
1138+
php_stream_wrapper_warn(wrapper, context, options, AuthFailed,
1139+
"Unable to connect to %s", url);
11601140
goto rmdir_errexit;
11611141
}
11621142

11631143
if (resource->path == NULL) {
1164-
if (options & REPORT_ERRORS) {
1165-
php_stream_wrapper_warn(wrapper, context, options, InvalidPath,
1166-
"Invalid path provided in %s", url);
1167-
}
1144+
php_stream_wrapper_warn(wrapper, context, options, InvalidPath,
1145+
"Invalid path provided in %s", url);
11681146
goto rmdir_errexit;
11691147
}
11701148

11711149
php_stream_printf(stream, "RMD %s\r\n", ZSTR_VAL(resource->path));
11721150
result = GET_FTP_RESULT(stream);
11731151

11741152
if (result < 200 || result > 299) {
1175-
if (options & REPORT_ERRORS) {
1176-
php_stream_wrapper_warn(wrapper, context, options, RmdirFailed,
1177-
"%s", tmp_line);
1178-
}
1153+
php_stream_wrapper_warn(wrapper, context, options, RmdirFailed,
1154+
"%s", tmp_line);
11791155
goto rmdir_errexit;
11801156
}
11811157

ext/standard/php_fopen_wrapper.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,9 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
220220
php_stream_input_t *input;
221221

222222
if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) {
223-
if (options & REPORT_ERRORS) {
224-
php_stream_wrapper_warn(wrapper, context, options,
225-
Disabled,
226-
"URL file-access is disabled in the server configuration");
227-
}
223+
php_stream_wrapper_warn(wrapper, context, options,
224+
Disabled,
225+
"URL file-access is disabled in the server configuration");
228226
return NULL;
229227
}
230228

@@ -241,11 +239,9 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
241239

242240
if (!strcasecmp(path, "stdin")) {
243241
if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) {
244-
if (options & REPORT_ERRORS) {
245-
php_stream_wrapper_warn(wrapper, context, options,
246-
Disabled,
247-
"URL file-access is disabled in the server configuration");
248-
}
242+
php_stream_wrapper_warn(wrapper, context, options,
243+
Disabled,
244+
"URL file-access is disabled in the server configuration");
249245
return NULL;
250246
}
251247
if (!strcmp(sapi_module.name, "cli")) {
@@ -302,20 +298,16 @@ static php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const c
302298
int dtablesize;
303299

304300
if (strcmp(sapi_module.name, "cli")) {
305-
if (options & REPORT_ERRORS) {
306-
php_stream_wrapper_warn(wrapper, context, options,
307-
Disabled,
308-
"Direct access to file descriptors is only available from command-line PHP");
309-
}
301+
php_stream_wrapper_warn(wrapper, context, options,
302+
Disabled,
303+
"Direct access to file descriptors is only available from command-line PHP");
310304
return NULL;
311305
}
312306

313307
if ((options & STREAM_OPEN_FOR_INCLUDE) && !PG(allow_url_include) ) {
314-
if (options & REPORT_ERRORS) {
315-
php_stream_wrapper_warn(wrapper, context, options,
316-
Disabled,
317-
"URL file-access is disabled in the server configuration");
318-
}
308+
php_stream_wrapper_warn(wrapper, context, options,
309+
Disabled,
310+
"URL file-access is disabled in the server configuration");
319311
return NULL;
320312
}
321313

main/streams/plain_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
14821482
}
14831483

14841484
int ret = VCWD_MKDIR(dir, (mode_t)mode);
1485-
if (ret < 0 && (options & REPORT_ERRORS)) {
1485+
if (ret < 0) {
14861486
php_stream_wrapper_warn(wrapper, context, options,
14871487
MkdirFailed, "%s", strerror(errno));
14881488
return 0;

main/streams/streams.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,11 +1909,10 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
19091909
#else
19101910
if (!localhost && path[n+3] != '\0' && path[n+3] != '/') {
19111911
#endif
1912-
if (options & REPORT_ERRORS) {
1913-
php_stream_wrapper_warn(plain_files_wrapper, NULL, options,
1914-
ProtocolUnsupported,
1915-
"Remote host file access not supported, %s", path);
1916-
}
1912+
php_stream_wrapper_warn(plain_files_wrapper, NULL, options,
1913+
ProtocolUnsupported,
1914+
"Remote host file access not supported, %s", path);
1915+
19171916
return NULL;
19181917
}
19191918

@@ -1950,11 +1949,9 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
19501949
return wrapper;
19511950
}
19521951

1953-
if (options & REPORT_ERRORS) {
1954-
php_stream_wrapper_warn(plain_files_wrapper, NULL, options,
1955-
Disabled,
1956-
"file:// wrapper is disabled in the server configuration");
1957-
}
1952+
php_stream_wrapper_warn(plain_files_wrapper, NULL, options,
1953+
Disabled,
1954+
"file:// wrapper is disabled in the server configuration");
19581955
return NULL;
19591956
}
19601957

0 commit comments

Comments
 (0)