[PHP-CVS] cvs: php-src(PHP_5_1) /main php_variables.c
dmitry Tue Apr 18 06:58:43 2006 UTC Modified files: (Branch: PHP_5_1) /php-src/main php_variables.c Log: Fixed memory leaks http://cvs.php.net/viewcvs.cgi/php-src/main/php_variables.c?r1=1.104.2.8r2=1.104.2.9diff_format=u Index: php-src/main/php_variables.c diff -u php-src/main/php_variables.c:1.104.2.8 php-src/main/php_variables.c:1.104.2.9 --- php-src/main/php_variables.c:1.104.2.8 Fri Apr 7 13:57:27 2006 +++ php-src/main/php_variables.cTue Apr 18 06:58:43 2006 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: php_variables.c,v 1.104.2.8 2006/04/07 13:57:27 dmitry Exp $ */ +/* $Id: php_variables.c,v 1.104.2.9 2006/04/18 06:58:43 dmitry Exp $ */ #include stdio.h #include php.h @@ -421,10 +421,8 @@ return; } - ALLOC_ZVAL(arr); + ALLOC_INIT_ZVAL(arr); array_init(arr); - arr-is_ref = 0; - arr-refcount = 0; /* Prepare argv */ if (SG(request_info).argc) { /* are we in cli sapi? */ @@ -470,15 +468,13 @@ } /* prepare argc */ - ALLOC_ZVAL(argc); + ALLOC_INIT_ZVAL(argc); if (SG(request_info).argc) { Z_LVAL_P(argc) = SG(request_info).argc; } else { Z_LVAL_P(argc) = count; } Z_TYPE_P(argc) = IS_LONG; - argc-is_ref = 0; - argc-refcount = 0; if (PG(register_globals) || SG(request_info).argc) { arr-refcount++; @@ -492,6 +488,8 @@ zend_hash_update(Z_ARRVAL_P(track_vars_array), argv, sizeof(argv), arr, sizeof(zval *), NULL); zend_hash_update(Z_ARRVAL_P(track_vars_array), argc, sizeof(argc), argc, sizeof(zval *), NULL); } + zval_ptr_dtor(arr); + zval_ptr_dtor(argc); } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_1) /main php_variables.c
dmitry Fri Apr 7 13:57:27 2006 UTC Modified files: (Branch: PHP_5_1) /php-src/main php_variables.c Log: Optimization http://cvs.php.net/viewcvs.cgi/php-src/main/php_variables.c?r1=1.104.2.7r2=1.104.2.8diff_format=u Index: php-src/main/php_variables.c diff -u php-src/main/php_variables.c:1.104.2.7 php-src/main/php_variables.c:1.104.2.8 --- php-src/main/php_variables.c:1.104.2.7 Mon Mar 20 10:15:02 2006 +++ php-src/main/php_variables.cFri Apr 7 13:57:27 2006 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: php_variables.c,v 1.104.2.7 2006/03/20 10:15:02 dmitry Exp $ */ +/* $Id: php_variables.c,v 1.104.2.8 2006/04/07 13:57:27 dmitry Exp $ */ #include stdio.h #include php.h @@ -64,7 +64,7 @@ char *index, *escaped_index = NULL; int var_len, index_len; zval *gpc_element, **gpc_element_p; - zend_bool is_array; + zend_bool is_array = 0; HashTable *symtable1 = NULL; assert(var != NULL); @@ -83,44 +83,43 @@ /* * Prepare variable name */ - ip = strchr(var, '['); - if (ip) { - is_array = 1; - *ip = 0; - } else { - is_array = 0; - } + /* ignore leading spaces in the variable name */ while (*var *var==' ') { var++; } - var_len = strlen(var); + + /* ensure that we don't have spaces or dots in the variable name (not binary safe) */ + for (p = var; *p; p++) { + if (*p == ' ' || *p == '.') { + *p='_'; + } else if (*p == '[') { + is_array = 1; + ip = p; + *p = 0; + break; + } + } + var_len = p - var; + if (var_len==0) { /* empty variable name, or variable name with a space in it */ zval_dtor(val); return; } /* GLOBALS hijack attempt, reject parameter */ - if (symtable1 == EG(active_symbol_table) !strcmp(GLOBALS, var)) { + if (symtable1 == EG(active_symbol_table) + var_len == sizeof(GLOBALS)-1 + !memcmp(var, GLOBALS, sizeof(GLOBALS)-1)) { zval_dtor(val); return; } - /* ensure that we don't have spaces or dots in the variable name (not binary safe) */ - for (p=var; *p; p++) { - switch (*p) { - case ' ': - case '.': - *p='_'; - break; - } - } - index = var; index_len = var_len; - while (1) { - if (is_array) { + if (is_array) { + while (1) { char *index_s; int new_idx_len = 0; @@ -181,41 +180,36 @@ } else { is_array = 0; } - } else { + } + } else { plain_var: - MAKE_STD_ZVAL(gpc_element); - gpc_element-value = val-value; - Z_TYPE_P(gpc_element) = Z_TYPE_P(val); - if (!index) { - zend_hash_next_index_insert(symtable1, gpc_element, sizeof(zval *), (void **) gpc_element_p); + MAKE_STD_ZVAL(gpc_element); + gpc_element-value = val-value; + Z_TYPE_P(gpc_element) = Z_TYPE_P(val); + if (!index) { + zend_hash_next_index_insert(symtable1, gpc_element, sizeof(zval *), (void **) gpc_element_p); + } else { + if (PG(magic_quotes_gpc)) { + escaped_index = php_addslashes(index, index_len, index_len, 0 TSRMLS_CC); + } else { + escaped_index = index; + } + /* +* According to rfc2965, more specific paths are listed above the less specific ones. +* If we encounter a duplicate cookie name, we should skip it, since it is not possible +* to have the same (plain text) cookie name for the same path and we should not overwrite +* more specific cookies with the less specific ones. +*/ + if (PG(http_globals)[TRACK_VARS_COOKIE] + symtable1 == Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) + zend_symtable_exists(symtable1, escaped_index, index_len + 1)) { + zval_ptr_dtor(gpc_element); } else { - zval **tmp; - -
[PHP-CVS] cvs: php-src(PHP_5_1) /main php_variables.c
dmitry Mon Mar 20 10:15:02 2006 UTC Modified files: (Branch: PHP_5_1) /php-src/main php_variables.c Log: Fixed register_argc_argv behavior. Now it behave in the same way as before in all combinations with register_globals, register_long_arrays, variables_order and auto_globals_jit. http://cvs.php.net/viewcvs.cgi/php-src/main/php_variables.c?r1=1.104.2.6r2=1.104.2.7diff_format=u Index: php-src/main/php_variables.c diff -u php-src/main/php_variables.c:1.104.2.6 php-src/main/php_variables.c:1.104.2.7 --- php-src/main/php_variables.c:1.104.2.6 Fri Mar 17 08:58:51 2006 +++ php-src/main/php_variables.cMon Mar 20 10:15:02 2006 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: php_variables.c,v 1.104.2.6 2006/03/17 08:58:51 dmitry Exp $ */ +/* $Id: php_variables.c,v 1.104.2.7 2006/03/20 10:15:02 dmitry Exp $ */ #include stdio.h #include php.h @@ -736,6 +736,23 @@ { if (PG(variables_order) (strchr(PG(variables_order),'S') || strchr(PG(variables_order),'s'))) { php_register_server_variables(TSRMLS_C); + + if (PG(register_argc_argv)) { + if (SG(request_info).argc) { + zval **argc, **argv; + + if (zend_hash_find(EG(symbol_table), argc, sizeof(argc), (void**)argc) == SUCCESS + zend_hash_find(EG(symbol_table), argv, sizeof(argv), (void**)argv) == SUCCESS) { + (*argc)-refcount++; + (*argv)-refcount++; + zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), argv, sizeof(argv), argv, sizeof(zval *), NULL); + zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), argc, sizeof(argc), argc, sizeof(zval *), NULL); + } + } else { + php_build_argv(SG(request_info).query_string, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC); + } + } + } else { zval *server_vars=NULL; ALLOC_ZVAL(server_vars); @@ -754,19 +771,7 @@ zend_hash_update(EG(symbol_table), HTTP_SERVER_VARS, sizeof(HTTP_SERVER_VARS), PG(http_globals)[TRACK_VARS_SERVER], sizeof(zval *), NULL); PG(http_globals)[TRACK_VARS_SERVER]-refcount++; } - - if (PG(register_argc_argv)) { - zval **argc, **argv; - - if (zend_hash_find(EG(symbol_table), argc, sizeof(argc), (void**)argc) == SUCCESS - zend_hash_find(EG(symbol_table), argv, sizeof(argv), (void**)argv) == SUCCESS) { - (*argc)-refcount++; - (*argv)-refcount++; - zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), argv, sizeof(argv), argv, sizeof(zval *), NULL); - zend_hash_update(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), argc, sizeof(argc), argc, sizeof(zval *), NULL); - } - } - + return 0; /* don't rearm */ } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src(PHP_5_1) /main php_variables.c
rasmus Wed Aug 10 19:33:12 2005 EDT Modified files: (Branch: PHP_5_1) /php-src/main php_variables.c Log: Minor consistency cleanup http://cvs.php.net/diff.php/php-src/main/php_variables.c?r1=1.104r2=1.104.2.1ty=u Index: php-src/main/php_variables.c diff -u php-src/main/php_variables.c:1.104 php-src/main/php_variables.c:1.104.2.1 --- php-src/main/php_variables.c:1.104 Wed Aug 3 10:08:38 2005 +++ php-src/main/php_variables.cWed Aug 10 19:33:10 2005 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: php_variables.c,v 1.104 2005/08/03 14:08:38 sniper Exp $ */ +/* $Id: php_variables.c,v 1.104.2.1 2005/08/10 23:33:10 rasmus Exp $ */ #include stdio.h #include php.h @@ -61,7 +61,7 @@ { char *p = NULL; char *ip; /* index pointer */ - char *index; + char *index, *escaped_index = NULL; int var_len, index_len; zval *gpc_element, **gpc_element_p; zend_bool is_array; @@ -114,7 +114,7 @@ while (1) { if (is_array) { - char *escaped_index = NULL, *index_s; + char *index_s; int new_idx_len = 0; ip++; @@ -183,7 +183,6 @@ zend_hash_next_index_insert(symtable1, gpc_element, sizeof(zval *), (void **) gpc_element_p); } else { zval **tmp; - char *escaped_index; if (PG(magic_quotes_gpc)) { escaped_index = php_addslashes(index, index_len, index_len, 0 TSRMLS_CC); @@ -198,13 +197,13 @@ */ if (PG(http_globals)[TRACK_VARS_COOKIE] symtable1 == Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]) zend_symtable_find(symtable1, escaped_index, index_len+1, (void **) tmp) != FAILURE) { - if (PG(magic_quotes_gpc)) { + if (index != escaped_index) { efree(escaped_index); } break; } zend_symtable_update(symtable1, escaped_index, index_len + 1, gpc_element, sizeof(zval *), (void **) gpc_element_p); - if (PG(magic_quotes_gpc)) { + if (index != escaped_index) { efree(escaped_index); } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php