pollita         Mon Jun 21 14:58:55 2004 EDT

  Modified files:              
    /php-src/ext/standard       basic_functions.c file.h 
    /php-src/main/streams       userspace.c streams.c 
    /php-src/main       php_streams.h 
  Log:
  BugFix#28868: Wrapper hash not thread-safe.
  
  Userdefined wrappers were being registered into a global wrapper hash
  which can cross threads.  Termination of once instance then has the
  potential to leave an active stream in another instance with no wrapper
  leading to segfault.
  
  
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.670&r2=1.671&ty=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.670 
php-src/ext/standard/basic_functions.c:1.671
--- php-src/ext/standard/basic_functions.c:1.670        Sun Jun 20 05:37:35 2004
+++ php-src/ext/standard/basic_functions.c      Mon Jun 21 14:58:54 2004
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.670 2004/06/20 09:37:35 helly Exp $ */
+/* $Id: basic_functions.c,v 1.671 2004/06/21 18:58:54 pollita Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -1160,6 +1160,9 @@
        /* Setup default context */
        FG(default_context) = NULL;
 
+       /* Default to global wrappers only */
+       FG(stream_wrappers) = NULL;
+
        return SUCCESS;
 }
 
@@ -1195,6 +1198,12 @@
                zend_llist_destroy(BG(user_tick_functions));
                efree(BG(user_tick_functions));
                BG(user_tick_functions) = NULL;
+       }
+
+       if (FG(stream_wrappers)) {
+               zend_hash_destroy(FG(stream_wrappers));
+               efree(FG(stream_wrappers));
+               FG(stream_wrappers) = NULL;
        }
 
        PHP_RSHUTDOWN(user_filters)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
http://cvs.php.net/diff.php/php-src/ext/standard/file.h?r1=1.88&r2=1.89&ty=u
Index: php-src/ext/standard/file.h
diff -u php-src/ext/standard/file.h:1.88 php-src/ext/standard/file.h:1.89
--- php-src/ext/standard/file.h:1.88    Thu Jan  8 12:32:51 2004
+++ php-src/ext/standard/file.h Mon Jun 21 14:58:54 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: file.h,v 1.88 2004/01/08 17:32:51 sniper Exp $ */
+/* $Id: file.h,v 1.89 2004/06/21 18:58:54 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */
 
@@ -113,6 +113,7 @@
        char *user_agent;
        char *user_stream_current_filename; /* for simple recursion protection */
        php_stream_context *default_context;
+       HashTable *stream_wrappers;                     /* per-request copy of 
url_stream_wrappers_hash */
 } php_file_globals;
 
 #ifdef ZTS
http://cvs.php.net/diff.php/php-src/main/streams/userspace.c?r1=1.25&r2=1.26&ty=u
Index: php-src/main/streams/userspace.c
diff -u php-src/main/streams/userspace.c:1.25 php-src/main/streams/userspace.c:1.26
--- php-src/main/streams/userspace.c:1.25       Thu May  6 10:29:32 2004
+++ php-src/main/streams/userspace.c    Mon Jun 21 14:58:55 2004
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: userspace.c,v 1.25 2004/05/06 14:29:32 pollita Exp $ */
+/* $Id: userspace.c,v 1.26 2004/06/21 18:58:55 pollita Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -59,7 +59,6 @@
 {
        struct php_user_stream_wrapper * uwrap = (struct 
php_user_stream_wrapper*)rsrc->ptr;
 
-       php_unregister_url_stream_wrapper(uwrap->protoname TSRMLS_CC);
        efree(uwrap->protoname);
        efree(uwrap->classname);
        efree(uwrap);
@@ -415,10 +414,10 @@
        uwrap->wrapper.abstract = uwrap;
 
        rsrc_id = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols);
-       
+
        if (zend_lookup_class(uwrap->classname, classname_len, 
(zend_class_entry***)&uwrap->ce TSRMLS_CC) == SUCCESS) {
                uwrap->ce = *(zend_class_entry**)uwrap->ce;
-               if (php_register_url_stream_wrapper(protocol, &uwrap->wrapper 
TSRMLS_CC) == SUCCESS) {
+               if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper 
TSRMLS_CC) == SUCCESS) {
                        RETURN_TRUE;
                } else {
                        /* We failed.  But why? */
http://cvs.php.net/diff.php/php-src/main/streams/streams.c?r1=1.55&r2=1.56&ty=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.55 php-src/main/streams/streams.c:1.56
--- php-src/main/streams/streams.c:1.55 Thu May 27 09:04:14 2004
+++ php-src/main/streams/streams.c      Mon Jun 21 14:58:55 2004
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.55 2004/05/27 13:04:14 wez Exp $ */
+/* $Id: streams.c,v 1.56 2004/06/21 18:58:55 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -34,6 +34,7 @@
 #include "php_streams_int.h"
 
 /* {{{ resource and registration code */
+/* Global wrapper hash, copied to FG(stream_wrappers) on registration of volatile 
wrapper */
 static HashTable url_stream_wrappers_hash;
 static int le_stream = FAILURE; /* true global */
 static int le_pstream = FAILURE; /* true global */
@@ -48,9 +49,9 @@
        return le_pstream;
 }
 
-PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash()
+PHPAPI HashTable *_php_stream_get_url_stream_wrappers_hash(TSRMLS_D)
 {
-       return &url_stream_wrappers_hash;
+       return (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash);
 }
 
 static int _php_stream_release_context(list_entry *le, void *pContext TSRMLS_DC)
@@ -1374,6 +1375,7 @@
        return SUCCESS;
 }
 
+/* API for registering GLOBAL wrappers */
 PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper 
*wrapper TSRMLS_DC)
 {
        return zend_hash_add(&url_stream_wrappers_hash, protocol, strlen(protocol), 
wrapper, sizeof(*wrapper), NULL);
@@ -1383,11 +1385,27 @@
 {
        return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol));
 }
+
+/* API for registering VOLATILE wrappers */
+PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, 
php_stream_wrapper *wrapper TSRMLS_DC)
+{
+       if (!FG(stream_wrappers)) {
+               php_stream_wrapper tmpwrapper;
+
+               FG(stream_wrappers) = emalloc(sizeof(HashTable));
+               zend_hash_init(FG(stream_wrappers), 0, NULL, NULL, 1);
+               zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, 
&tmpwrapper, sizeof(php_stream_wrapper));
+       }
+
+       return zend_hash_add(FG(stream_wrappers), protocol, strlen(protocol), wrapper, 
sizeof(*wrapper), NULL);
+}
+
 /* }}} */
 
 /* {{{ php_stream_locate_url_wrapper */
 PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char 
**path_for_open, int options TSRMLS_DC)
 {
+       HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : 
&url_stream_wrappers_hash);
        php_stream_wrapper *wrapper = NULL;
        const char *p, *protocol = NULL;
        int n = 0;
@@ -1414,7 +1432,7 @@
        }
 
        if (protocol)   {
-               if (FAILURE == zend_hash_find(&url_stream_wrappers_hash, 
(char*)protocol, n, (void**)&wrapper)) {
+               if (FAILURE == zend_hash_find(wrapper_hash, (char*)protocol, n, 
(void**)&wrapper))      {
                        char wrapper_name[32];
 
                        if (n >= sizeof(wrapper_name))
http://cvs.php.net/diff.php/php-src/main/php_streams.h?r1=1.93&r2=1.94&ty=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.93 php-src/main/php_streams.h:1.94
--- php-src/main/php_streams.h:1.93     Fri Feb 20 03:04:30 2004
+++ php-src/main/php_streams.h  Mon Jun 21 14:58:55 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_streams.h,v 1.93 2004/02/20 08:04:30 hholzgra Exp $ */
+/* $Id: php_streams.h,v 1.94 2004/06/21 18:58:55 pollita Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -509,6 +509,7 @@
 BEGIN_EXTERN_C()
 PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper 
*wrapper TSRMLS_DC);
 PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC);
+PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, 
php_stream_wrapper *wrapper TSRMLS_DC);
 PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, 
char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
 PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char 
**path_for_open, int options TSRMLS_DC);
 PHPAPI char *php_stream_locate_eol(php_stream *stream, char *buf, size_t buf_len 
TSRMLS_DC);
@@ -538,7 +539,8 @@
 #define php_stream_make_seekable(origstream, newstream, flags) 
_php_stream_make_seekable((origstream), (newstream), (flags) STREAMS_CC TSRMLS_CC)
 
 /* Give other modules access to the url_stream_wrappers_hash and stream_filters_hash 
*/
-PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash();
+PHPAPI HashTable *_php_stream_get_url_stream_wrappers_hash(TSRMLS_D);
+#define php_stream_get_url_stream_wrappers_hash()      
_php_stream_get_url_stream_wrappers_hash(TSRMLS_C)
 PHPAPI HashTable *php_get_stream_filters_hash();
 END_EXTERN_C()
 #endif

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to