pollita         Mon Jun 21 15:33:48 2004 EDT

  Modified files:              (Branch: PHP_4_3)
    /php-src/ext/standard       basic_functions.c file.h 
    /php-src/main       user_streams.c streams.c php_streams.h 
  Log:
  MFH: BugFix#28868 Wrapper hash not thread-safe
  
  
http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.543.2.38&r2=1.543.2.39&ty=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.543.2.38 
php-src/ext/standard/basic_functions.c:1.543.2.39
--- php-src/ext/standard/basic_functions.c:1.543.2.38   Mon May 24 13:02:31 2004
+++ php-src/ext/standard/basic_functions.c      Mon Jun 21 15:33:47 2004
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.543.2.38 2004/05/24 17:02:31 iliaa Exp $ */
+/* $Id: basic_functions.c,v 1.543.2.39 2004/06/21 19:33:47 pollita Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -1188,6 +1188,9 @@
        /* Reset magic_quotes_runtime */
        PG(magic_quotes_runtime) = INI_BOOL("magic_quotes_runtime");
 
+       /* Default to global wrappers only */
+       FG(stream_wrappers) = NULL;
+
        return SUCCESS;
 }
 
@@ -1210,6 +1213,12 @@
                setlocale(LC_CTYPE, "");
        }
        STR_FREE(BG(locale_string));
+
+       if (FG(stream_wrappers)) {
+               zend_hash_destroy(FG(stream_wrappers));
+               efree(FG(stream_wrappers));
+               FG(stream_wrappers) = NULL;
+       }
 
        PHP_RSHUTDOWN(fsock) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
        PHP_RSHUTDOWN(filestat) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
http://cvs.php.net/diff.php/php-src/ext/standard/file.h?r1=1.70.2.5&r2=1.70.2.6&ty=u
Index: php-src/ext/standard/file.h
diff -u php-src/ext/standard/file.h:1.70.2.5 php-src/ext/standard/file.h:1.70.2.6
--- php-src/ext/standard/file.h:1.70.2.5        Mon Sep 29 10:04:16 2003
+++ php-src/ext/standard/file.h Mon Jun 21 15:33:47 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: file.h,v 1.70.2.5 2003/09/29 14:04:16 stas Exp $ */
+/* $Id: file.h,v 1.70.2.6 2004/06/21 19:33:47 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */
 
@@ -118,6 +118,7 @@
        long default_socket_timeout;
        char *user_agent;
        char *user_stream_current_filename; /* for simple recursion protection */
+       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/user_streams.c?r1=1.29.2.3&r2=1.29.2.4&ty=u
Index: php-src/main/user_streams.c
diff -u php-src/main/user_streams.c:1.29.2.3 php-src/main/user_streams.c:1.29.2.4
--- php-src/main/user_streams.c:1.29.2.3        Wed Feb 11 12:09:09 2004
+++ php-src/main/user_streams.c Mon Jun 21 15:33:47 2004
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: user_streams.c,v 1.29.2.3 2004/02/11 17:09:09 iliaa Exp $ */
+/* $Id: user_streams.c,v 1.29.2.4 2004/06/21 19:33:47 pollita Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -51,7 +51,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);
@@ -361,7 +360,7 @@
 #ifdef ZEND_ENGINE_2
                uwrap->ce = *(zend_class_entry**)uwrap->ce;
 #endif
-               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 {
http://cvs.php.net/diff.php/php-src/main/streams.c?r1=1.125.2.89&r2=1.125.2.90&ty=u
Index: php-src/main/streams.c
diff -u php-src/main/streams.c:1.125.2.89 php-src/main/streams.c:1.125.2.90
--- php-src/main/streams.c:1.125.2.89   Wed May 12 06:46:30 2004
+++ php-src/main/streams.c      Mon Jun 21 15:33:48 2004
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.125.2.89 2004/05/12 10:46:30 wez Exp $ */
+/* $Id: streams.c,v 1.125.2.90 2004/06/21 19:33:48 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -96,6 +96,7 @@
 # define PHP_STREAM_COOKIE_FUNCTIONS   stream_cookie_functions
 #endif
        
+/* 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 */
@@ -2335,6 +2336,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);
@@ -2344,6 +2346,20 @@
 {
        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);
+}
 /* }}} */
 
 
@@ -2459,6 +2475,7 @@
 
 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;
@@ -2485,7 +2502,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 (options & REPORT_ERRORS) {
@@ -2911,9 +2928,9 @@
        return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, 
strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL);
 }
 
-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);
 }
 
 /*
http://cvs.php.net/diff.php/php-src/main/php_streams.h?r1=1.61.2.16&r2=1.61.2.17&ty=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.61.2.16 php-src/main/php_streams.h:1.61.2.17
--- php-src/main/php_streams.h:1.61.2.16        Tue Jul 29 14:26:59 2003
+++ php-src/main/php_streams.h  Mon Jun 21 15:33:48 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_streams.h,v 1.61.2.16 2003/07/29 18:26:59 iliaa Exp $ */
+/* $Id: php_streams.h,v 1.61.2.17 2004/06/21 19:33:48 pollita Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -530,6 +530,7 @@
 
 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);
@@ -627,7 +628,8 @@
        
 
 /* Give other modules access to the url_stream_wrappers_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)
 
 #endif
 

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

Reply via email to