]> granicus.if.org Git - php/commitdiff
Avoid strings duplication (zend_hash* and printf may work with non zero terminated...
authorDmitry Stogov <dmitry@zend.com>
Thu, 30 Nov 2017 20:29:21 +0000 (23:29 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 30 Nov 2017 20:29:21 +0000 (23:29 +0300)
main/streams/memory.c
main/streams/streams.c
main/streams/transports.c

index c21277815102edefc99c3e4c3a4c3a33674cacdc..d6b0e5604b9847babb4c2d4d462e1e674467c80d 100644 (file)
@@ -638,7 +638,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
 {
        php_stream *stream;
        php_stream_temp_data *ts;
-       char *comma, *semi, *sep, *key;
+       char *comma, *semi, *sep;
        size_t mlen, dlen, plen, vlen, ilen;
        zend_off_t newoffs;
        zval meta;
@@ -710,11 +710,9 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
                        /* found parameter ... the heart of cs ppl lies in +1/-1 or was it +2 this time? */
                        plen = sep - path;
                        vlen = (semi ? (size_t)(semi - sep) : (mlen - plen)) - 1 /* '=' */;
-                       key = estrndup(path, plen);
-                       if (plen != sizeof("mediatype")-1 || memcmp(key, "mediatype", sizeof("mediatype")-1)) {
-                               add_assoc_stringl_ex(&meta, key, plen, sep + 1, vlen);
+                       if (plen != sizeof("mediatype")-1 || memcmp(path, "mediatype", sizeof("mediatype")-1)) {
+                               add_assoc_stringl_ex(&meta, path, plen, sep + 1, vlen);
                        }
-                       efree(key);
                        plen += vlen + 1;
                        mlen -= plen;
                        path += plen;
index 5f8acfde69137f0830117bbf20ffff9926a5a42d..c97ebd02397eea8edc8111d29462d154d6886214 100644 (file)
@@ -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;
        }
index 2bf4230870079efee90f47433e39526094eeeb3b..5a73aea1c0ec714b2230de6148edc1064f766370 100644 (file)
@@ -112,8 +112,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
        }
 
        if (protocol) {
-               char *tmp = estrndup(protocol, n);
-               if (NULL == (factory = zend_hash_str_find_ptr(&xport_hash, tmp, n))) {
+               if (NULL == (factory = zend_hash_str_find_ptr(&xport_hash, protocol, n))) {
                        char wrapper_name[32];
 
                        if (n >= sizeof(wrapper_name))
@@ -123,10 +122,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in
                        ERR_REPORT(error_string, "Unable to find the socket transport \"%s\" - did you forget to enable it when you configured PHP?",
                                        wrapper_name);
 
-                       efree(tmp);
                        return NULL;
                }
-               efree(tmp);
        }
 
        if (factory == NULL) {