summaryrefslogtreecommitdiff
path: root/main/streams/streams.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2017-11-30 23:29:21 +0300
committerDmitry Stogov <dmitry@zend.com>2017-11-30 23:29:21 +0300
commitaf7705bec2c57580d0baa219511f1827897d662d (patch)
treeca1bcc880adf36c3181326362e4432b05f8f8749 /main/streams/streams.c
parente221e7379ed34d33521dab1e3e6a93948df84aed (diff)
downloadphp-git-af7705bec2c57580d0baa219511f1827897d662d.tar.gz
Avoid strings duplication (zend_hash* and printf may work with non zero terminated strings)
Diffstat (limited to 'main/streams/streams.c')
-rw-r--r--main/streams/streams.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 5f8acfde69..c97ebd0239 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1742,10 +1742,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
}
if (protocol) {
- char *tmp = estrndup(protocol, n);
- if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) {
+ if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, protocol, n))) {
+ char *tmp = estrndup(protocol, n);
+
php_strtolower(tmp, n);
- if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) {
+ if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, tmp, n))) {
char wrapper_name[32];
if (n >= sizeof(wrapper_name)) {
@@ -1758,8 +1759,8 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
wrapper = NULL;
protocol = NULL;
}
+ efree(tmp);
}
- efree(tmp);
}
/* TODO: curl based streams probably support file:// properly */
if (!protocol || !strncasecmp(protocol, "file", n)) {
@@ -1833,13 +1834,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const
PG(in_user_include)) && !PG(allow_url_include)))) {
if (options & REPORT_ERRORS) {
/* protocol[n] probably isn't '\0' */
- char *protocol_dup = estrndup(protocol, n);
if (!PG(allow_url_fopen)) {
- php_error_docref(NULL, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_fopen=0", protocol_dup);
+ php_error_docref(NULL, E_WARNING, "%.*s:// wrapper is disabled in the server configuration by allow_url_fopen=0", (int)n, protocol);
} else {
- php_error_docref(NULL, E_WARNING, "%s:// wrapper is disabled in the server configuration by allow_url_include=0", protocol_dup);
+ php_error_docref(NULL, E_WARNING, "%.*s:// wrapper is disabled in the server configuration by allow_url_include=0", (int)n, protocol);
}
- efree(protocol_dup);
}
return NULL;
}