@@ -76,6 +76,8 @@ PHP_INI_BEGIN()
76
76
PHP_INI_ENTRY ("session.extern_referer_check" , "" , PHP_INI_ALL , NULL )
77
77
PHP_INI_ENTRY ("session.entropy_file" , "" , PHP_INI_ALL , NULL )
78
78
PHP_INI_ENTRY ("session.entropy_length" , "0" , PHP_INI_ALL , NULL )
79
+ /* Commented out until future discussion */
80
+ /* PHP_INI_ENTRY("session.encode_sources", "globals,track", PHP_INI_ALL, NULL) */
79
81
PHP_INI_END ()
80
82
81
83
PS_SERIALIZER_FUNCS (php );
@@ -137,32 +139,57 @@ zend_module_entry session_module_entry = {
137
139
138
140
#define PS_DEL_VAR (name ) PS_DEL_VARL(name, strlen(name))
139
141
140
-
141
-
142
-
143
142
#define ENCODE_VARS \
144
143
char *key; \
145
144
ulong num_key; \
146
- zval **struc; \
147
- ELS_FETCH()
145
+ zval **struc \
146
+ PSLS_FETCH(); \
147
+ ELS_FETCH();
148
148
149
149
#define ENCODE_LOOP (code ) \
150
150
for(zend_hash_internal_pointer_reset(&PS(vars)); \
151
151
zend_hash_get_current_key(&PS(vars), &key, &num_key) == HASH_KEY_IS_STRING; \
152
152
zend_hash_move_forward(&PS(vars))) { \
153
- if(zend_hash_find(&EG(symbol_table), key, strlen(key) + 1, (void **) &struc) == SUCCESS) { \
153
+ if(php_get_session_var( key, strlen(key), &struc PSLS_CC ELS_CC ) == SUCCESS) { \
154
154
code; \
155
155
} \
156
156
efree(key); \
157
157
}
158
158
159
+ static void php_set_session_var (char * name , size_t namelen ,
160
+ zval * state_val PSLS_DC )
161
+ {
162
+ zval * state_val_copy ;
163
+ PLS_FETCH ();
164
+ ELS_FETCH ();
159
165
166
+ state_val_copy = (zval * )emalloc (sizeof (zval ));
167
+ * state_val_copy = * state_val ;
168
+ zval_copy_ctor (state_val_copy );
169
+
170
+ if (PG (gpc_globals ) && PG (track_vars )) {
171
+ zend_set_hash_symbol (state_val_copy , name , namelen , 1 , 2 , PS (http_state_vars )-> value .ht , & EG (symbol_table ));
172
+ } else {
173
+ if (PG (gpc_globals )) {
174
+ zend_set_hash_symbol (state_val_copy , name , namelen , 0 , 1 , PS (http_state_vars )-> value .ht );
175
+ }
176
+
177
+ if (PG (track_vars )) {
178
+ zend_set_hash_symbol (state_val_copy , name , namelen , 0 , 1 , & EG (symbol_table ));
179
+ }
180
+ }
181
+ }
182
+
183
+ static int php_get_session_var (char * name , size_t namelen , zval * * * state_var PSLS_DC ELS_DC )
184
+ {
185
+ return zend_hash_find (& EG (symbol_table ), name , namelen + 1 , (void * * )state_var );
186
+ }
160
187
161
188
PS_SERIALIZER_ENCODE_FUNC (php )
162
189
{
163
- pval * buf ;
190
+ zval * buf ;
164
191
char strbuf [MAX_STR + 1 ];
165
- ENCODE_VARS ;
192
+ ENCODE_VARS
166
193
167
194
buf = ecalloc (sizeof (* buf ), 1 );
168
195
buf -> type = IS_STRING ;
@@ -189,11 +216,11 @@ PS_SERIALIZER_DECODE_FUNC(php)
189
216
const char * p , * q ;
190
217
char * name ;
191
218
const char * endptr = val + vallen ;
192
- pval * current ;
219
+ zval * current ;
193
220
int namelen ;
194
221
int has_value ;
195
- ELS_FETCH ();
196
222
223
+ current = (zval * ) ecalloc (sizeof (zval ), 1 );
197
224
for (p = q = val ; (p < endptr ) && (q = strchr (p , '|' )); p = q ) {
198
225
if (p [0 ] == '!' ) {
199
226
p ++ ;
@@ -207,18 +234,15 @@ PS_SERIALIZER_DECODE_FUNC(php)
207
234
q ++ ;
208
235
209
236
if (has_value ) {
210
- current = (pval * ) ecalloc (sizeof (pval ), 1 );
211
-
212
237
if (php_var_unserialize (& current , & q , endptr )) {
213
- zend_hash_update (& EG (symbol_table ), name , namelen + 1 ,
214
- & current , sizeof (current ), NULL );
215
- } else {
216
- efree (current );
238
+ php_set_session_var (name , namelen , current PSLS_CC );
239
+ zval_dtor (current );
217
240
}
218
241
}
219
242
PS_ADD_VAR (name );
220
243
efree (name );
221
244
}
245
+ efree (current );
222
246
223
247
return SUCCESS ;
224
248
}
@@ -228,7 +252,7 @@ PS_SERIALIZER_DECODE_FUNC(php)
228
252
PS_SERIALIZER_ENCODE_FUNC (wddx )
229
253
{
230
254
wddx_packet * packet ;
231
- ENCODE_VARS ;
255
+ ENCODE_VARS
232
256
233
257
packet = _php_wddx_constructor ();
234
258
if (!packet ) return FAILURE ;
@@ -259,7 +283,6 @@ PS_SERIALIZER_DECODE_FUNC(wddx)
259
283
ulong idx ;
260
284
int hash_type ;
261
285
int dofree = 1 ;
262
- ELS_FETCH ();
263
286
264
287
if (vallen == 0 ) return FAILURE ;
265
288
@@ -278,9 +301,7 @@ PS_SERIALIZER_DECODE_FUNC(wddx)
278
301
key = tmp ;
279
302
dofree = 0 ;
280
303
case HASH_KEY_IS_STRING :
281
- zval_add_ref (ent );
282
- zend_hash_update (& EG (symbol_table ), key , strlen (key ) + 1 ,
283
- ent , sizeof (ent ), NULL );
304
+ php_set_session_var (key , strlen (key ), ent PSLS_CC )
284
305
PS_ADD_VAR (key );
285
306
if (dofree ) efree (key );
286
307
dofree = 1 ;
@@ -295,6 +316,20 @@ PS_SERIALIZER_DECODE_FUNC(wddx)
295
316
296
317
#endif
297
318
319
+ static void php_session_track_init ()
320
+ {
321
+ PSLS_FETCH ();
322
+ ELS_FETCH ();
323
+
324
+ if (zend_hash_find (& EG (symbol_table ), "HTTP_STATE_VARS" , sizeof ("HTTP_STATE_VARS" ),
325
+ (void * * )& PS (http_state_vars )) == FAILURE || PS (http_state_vars )-> type != IS_ARRAY ) {
326
+ MAKE_STD_ZVAL (PS (http_state_vars ));
327
+ array_init (PS (http_state_vars ));
328
+ ZEND_SET_GLOBAL_VAR_WITH_LENGTH ("HTTP_STATE_VARS" , sizeof ("HTTP_STATE_VARS" ), PS (http_state_vars ), 1 , 0 );
329
+ } else
330
+ zend_hash_clean (PS (http_state_vars )-> value .ht );
331
+ }
332
+
298
333
static char * _php_session_encode (int * newlen PSLS_DC )
299
334
{
300
335
char * ret = NULL ;
@@ -308,6 +343,8 @@ static char *_php_session_encode(int *newlen PSLS_DC)
308
343
309
344
static void _php_session_decode (const char * val , int vallen PSLS_DC )
310
345
{
346
+ if (PG (track_vars ))
347
+ php_session_track_init ();
311
348
PS (serializer )-> decode (val , vallen PSLS_CC );
312
349
}
313
350
@@ -733,19 +770,19 @@ PHP_FUNCTION(session_id)
733
770
/* }}} */
734
771
735
772
736
- /* {{{ static void php_register_var(zval** entry PSLS_DC) */
737
- static void php_register_var (zval * * entry PSLS_DC )
773
+ /* {{{ static void php_register_var(zval** entry PSLS_DC PLS_DC ) */
774
+ static void php_register_var (zval * * entry PSLS_DC PLS_DC )
738
775
{
739
776
zval * * value ;
740
777
741
778
if ((* entry )-> type == IS_ARRAY ) {
742
779
zend_hash_internal_pointer_reset ((* entry )-> value .ht );
743
780
744
781
while (zend_hash_get_current_data ((* entry )-> value .ht , (void * * )& value ) == SUCCESS ) {
745
- php_register_var (value PSLS_CC );
782
+ php_register_var (value PSLS_CC PLS_DC );
746
783
zend_hash_move_forward ((* entry )-> value .ht );
747
784
}
748
- } else {
785
+ } else if (! PG ( track_vars ) || strcmp (( * entry ) -> value . str . val , "HTTP_STATE_VARS" ) != 0 ) {
749
786
convert_to_string_ex (entry );
750
787
751
788
PS_ADD_VARL ((* entry )-> value .str .val , (* entry )-> value .str .len );
@@ -762,6 +799,7 @@ PHP_FUNCTION(session_register)
762
799
int argc = ARG_COUNT (ht );
763
800
int i ;
764
801
PSLS_FETCH ();
802
+ PLS_FETCH ();
765
803
766
804
if (argc <= 0 ) {
767
805
RETURN_FALSE ;
@@ -780,7 +818,7 @@ PHP_FUNCTION(session_register)
780
818
if ((* args [i ])-> type == IS_ARRAY ) {
781
819
SEPARATE_ZVAL (args [i ]);
782
820
}
783
- php_register_var (args [i ] PSLS_CC );
821
+ php_register_var (args [i ] PSLS_CC PLS_DC );
784
822
}
785
823
786
824
efree (args );
@@ -928,6 +966,8 @@ PHP_FUNCTION(session_unset)
928
966
929
967
static void php_rinit_session_globals (PSLS_D )
930
968
{
969
+ ELS_FETCH ();
970
+
931
971
PS (mod ) = _php_find_ps_module (INI_STR ("session.save_handler" ) PSLS_CC );
932
972
PS (serializer ) = \
933
973
_php_find_ps_serializer (INI_STR ("session.serialize_handler" ) PSLS_CC );
@@ -974,6 +1014,7 @@ void _php_session_auto_start(void *data)
974
1014
PHP_RINIT_FUNCTION (session )
975
1015
{
976
1016
PSLS_FETCH ();
1017
+ PLS_FETCH ();
977
1018
978
1019
php_rinit_session_globals (PSLS_C );
979
1020
@@ -983,7 +1024,7 @@ PHP_RINIT_FUNCTION(session)
983
1024
return SUCCESS ;
984
1025
}
985
1026
986
- if (INI_INT ("session.auto_start" )) {
1027
+ if (INI_INT ("session.auto_start" )) {
987
1028
php_register_post_request_startup (_php_session_auto_start , NULL );
988
1029
}
989
1030
0 commit comments