cvs: php4 /ext/session session.c

From: Date: Sun, 19 Nov 2000 13:13:36 +0000
Subject: cvs: php4 /ext/session session.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2679@lists.php.net to get a copy of this message
stas Sun Nov 19 05:13:36 2000 EDT Modified files: /php4/ext/session session.c Log: Fix #3261 - variables declared as "global" in function do not get the right value after session_start. Index: php4/ext/session/session.c diff -u php4/ext/session/session.c:1.184 php4/ext/session/session.c:1.185 --- php4/ext/session/session.c:1.184 Thu Nov 2 07:47:02 2000 +++ php4/ext/session/session.c Sun Nov 19 05:13:36 2000 @@ -220,12 +220,33 @@ state_val_copy->refcount = 0; if (PG(register_globals)) { - zend_set_hash_symbol(state_val_copy, name, namelen, 0, 2, Z_ARRVAL_P(PS(http_session_vars)), &EG(symbol_table)); - } else { - if (PG(register_globals)) { - zend_set_hash_symbol(state_val_copy, name, namelen, 0, 1, &EG(symbol_table)); - } + zval **old_symbol; + if(zend_hash_find(&EG(symbol_table),name,namelen+1,&old_symbol) == SUCCESS) { + /* + There where old one, we need to replace it accurately. + hash_update in zend_set_hash_symbol is not good, because + it will leave referenced variables (such as local instances + of a global variable) dangling. + */ + int is_ref, refcount; + + zval_dtor(*old_symbol); + + /* replace variable contents while saving is_ref and reference + count */ + is_ref = (*old_symbol)->is_ref; + refcount = (*old_symbol)->refcount; + **old_symbol = *state_val_copy; + (*old_symbol)->is_ref = is_ref; + (*old_symbol)->refcount = refcount; + FREE_ZVAL(state_val_copy); + + zend_set_hash_symbol(*old_symbol, name, namelen, 0, 1, Z_ARRVAL_P(PS(http_session_vars))); + } else { + zend_set_hash_symbol(state_val_copy, name, namelen, 0, 2, Z_ARRVAL_P(PS(http_session_vars)), &EG(symbol_table)); + } + } else { zend_set_hash_symbol(state_val_copy, name, namelen, 0, 1, Z_ARRVAL_P(PS(http_session_vars))); } }

« previous php.cvs (#2679) next »