]> granicus.if.org Git - php/commitdiff
MFH: add trailing '\0' to stream hashes
authorAntony Dovgal <tony2001@php.net>
Mon, 15 Jan 2007 17:07:08 +0000 (17:07 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 15 Jan 2007 17:07:08 +0000 (17:07 +0000)
ext/standard/user_filters.c
main/streams/filter.c
main/streams/streams.c
main/streams/transports.c
main/streams/userspace.c

index 66c0ab31f91ed74ccc24a24aba3165c84564aeb2..f10a441ea6ab57495e2e9a4b6d0024b202025e7f 100644 (file)
@@ -266,7 +266,7 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
 
        /* determine the classname/class entry */
        if (FAILURE == zend_hash_find(BG(user_filter_map), (char*)filtername,
-                               strlen(filtername), (void**)&fdat)) {
+                               strlen(filtername) + 1, (void**)&fdat)) {
                char *period;
 
                /* Userspace Filters using ambiguous wildcards could cause problems.
@@ -283,7 +283,7 @@ static php_stream_filter *user_filter_factory_create(const char *filtername,
                        while (period) {
                                *period = '\0';
                                strcat(wildcard, ".*");
-                               if (SUCCESS == zend_hash_find(BG(user_filter_map), wildcard, strlen(wildcard), (void**)&fdat)) {
+                               if (SUCCESS == zend_hash_find(BG(user_filter_map), wildcard, strlen(wildcard) + 1, (void**)&fdat)) {
                                        period = NULL;
                                } else {
                                        *period = '\0';
@@ -567,7 +567,7 @@ PHP_FUNCTION(stream_filter_register)
        fdat = ecalloc(1, sizeof(*fdat) + classname_len);
        memcpy(fdat->classname, classname, classname_len);
 
-       if (zend_hash_add(BG(user_filter_map), filtername, filtername_len, (void*)fdat,
+       if (zend_hash_add(BG(user_filter_map), filtername, filtername_len + 1, (void*)fdat,
                                sizeof(*fdat) + classname_len, NULL) == SUCCESS &&
                        php_stream_filter_register_factory_volatile(filtername, &user_filter_factory TSRMLS_CC) == SUCCESS) {
                RETVAL_TRUE;
index e2e969406203aafeb2f52f8fbd2fe6cd8b82ae05..50955f622977804126f312fb39c4df75af823670 100644 (file)
@@ -46,12 +46,12 @@ PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D)
 /* API for registering GLOBAL filters */
 PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC)
 {
-       return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL);
+       return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL);
 }
 
 PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC)
 {
-       return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern));
+       return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1);
 }
 
 /* API for registering VOLATILE wrappers */
@@ -65,7 +65,7 @@ PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern
                zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory));
        }
 
-       return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory, sizeof(*factory), NULL);
+       return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL);
 }
 
 /* Buckets */
@@ -259,7 +259,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
 
        n = strlen(filtername);
        
-       if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n, (void**)&factory)) {
+       if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n + 1, (void**)&factory)) {
                filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
        } else if ((period = strrchr(filtername, '.'))) {
                /* try a wildcard */
@@ -271,7 +271,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval
                while (period && !filter) {
                        *period = '\0';
                        strcat(wildname, ".*");
-                       if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname), (void**)&factory)) {
+                       if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname) + 1, (void**)&factory)) {
                                filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC);
                        }
 
index d4210cea6872dfde613119e5b200a2af25cfa2fe..9cd9cce6ef0aa92363999a4e372778ae58a6949e 100755 (executable)
@@ -1449,12 +1449,12 @@ PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *w
                return FAILURE;
        }
 
-       return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
+       return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
 }
 
 PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC)
 {
-       return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
+       return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1);
 }
 
 static void clone_wrapper_hash(TSRMLS_D)
@@ -1479,7 +1479,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w
                clone_wrapper_hash(TSRMLS_C);
        }
 
-       return zend_hash_add(FG(stream_wrappers), protocol, protocol_len, &wrapper, sizeof(wrapper), NULL);
+       return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL);
 }
 
 PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
@@ -1488,7 +1488,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol TSRMLS_DC)
                clone_wrapper_hash(TSRMLS_C);
        }
 
-       return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol));
+       return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1);
 }
 /* }}} */
 
@@ -1521,11 +1521,11 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Use of \"zlib:\" wrapper is deprecated; please use \"compress.zlib://\" instead.");
        }
 
-       if (protocol)   {
-               if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, (void**)&wrapperpp)) {
-                       char *tmp = estrndup(protocol, n);
+       if (protocol) {
+               char *tmp = estrndup(protocol, n);
+               if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) {
                        php_strtolower(tmp, n);
-                       if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n, (void**)&wrapperpp)) {
+                       if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) {
                                char wrapper_name[32];
 
                                if (n >= sizeof(wrapper_name)) {
@@ -1538,8 +1538,8 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
                                wrapperpp = NULL;
                                protocol = NULL;
                        }
-                       efree(tmp);
                }
+               efree(tmp);
        }
        /* TODO: curl based streams probably support file:// properly */
        if (!protocol || !strncasecmp(protocol, "file", n))     {
@@ -1588,7 +1588,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
                        }
                        
                        /* Check again, the original check might have not known the protocol name */
-                       if (zend_hash_find(wrapper_hash, "file", sizeof("file")-1, (void**)&wrapperpp) == SUCCESS) {
+                       if (zend_hash_find(wrapper_hash, "file", sizeof("file"), (void**)&wrapperpp) == SUCCESS) {
                                return *wrapperpp;
                        }
 
index 39dbea0f6a94eb5ba3456310c7d2a79076dff38c..54d0d9a9dacfdbe44c4374790efc4b9c9e90ec23 100644 (file)
@@ -31,12 +31,12 @@ PHPAPI HashTable *php_stream_xport_get_hash(void)
 
 PHPAPI int php_stream_xport_register(char *protocol, php_stream_transport_factory factory TSRMLS_DC)
 {
-       return zend_hash_update(&xport_hash, protocol, strlen(protocol), &factory, sizeof(factory), NULL);
+       return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL);
 }
 
 PHPAPI int php_stream_xport_unregister(char *protocol TSRMLS_DC)
 {
-       return zend_hash_del(&xport_hash, protocol, strlen(protocol));
+       return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1);
 }
 
 #define ERR_REPORT(out_err, fmt, arg) \
@@ -106,7 +106,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
        }
 
        if (protocol) {
-               if (FAILURE == zend_hash_find(&xport_hash, (char*)protocol, n, (void**)&factory)) {
+               char *tmp = estrndup(protocol, n);
+               if (FAILURE == zend_hash_find(&xport_hash, (char*)tmp, n + 1, (void**)&factory)) {
                        char wrapper_name[32];
 
                        if (n >= sizeof(wrapper_name))
@@ -116,8 +117,10 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int
                        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) {
index 6f92ff4ad40b07da6f349da81a652f44dac182ce..0fe6e213425e5505ab768de0ee3ed8ce1b564e96 100644 (file)
@@ -455,7 +455,7 @@ PHP_FUNCTION(stream_wrapper_register)
                        RETURN_TRUE;
                } else {
                        /* We failed.  But why? */
-                       if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len)) {
+                       if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len + 1)) {
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol);
                        } else {
                                /* Should never happen */
@@ -511,7 +511,7 @@ PHP_FUNCTION(stream_wrapper_restore)
                RETURN_TRUE;
        }
 
-       if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
+       if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len + 1, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol);
                RETURN_FALSE;
        }