[php-src] Issue #11783: Hashtable initialized at extension module level gets corrupted in processing first request itself

From: Date: Tue, 25 Jul 2023 09:33:23 +0000
Subject: [php-src] Issue #11783: Hashtable initialized at extension module level gets corrupted in processing first request itself
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245027@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11783 Author: HeenaBansal20 ### Description Here my struct member zend_long is persistent at each request but not hashtable keys and values, However a strange thing is number of elements are consistent but values are corrupted. The following code: ``` ZEND_BEGIN_MODULE_GLOBALS(myextension) { struct { zend_long matcher; HashTable *list; }mystruct; } my_ctor() { ALLOC_HASHTABLE(myextension_G(mystruct.list)); zend_hash_init(myextension_G(mystruct.list), 0, NULL, ZVAL_PTR_DTOR, 0); // tried with changing last param as 1 too to keep it persistent but no change parse_mystruct_value_from_ini(); } //This is the method to populate values in my hash table from customized ini settings. static void parse_mystruct_value_from_ini() { char *list = emalloc(strlen(INI_STR("structlist")) + 1); strcpy(list, INI_STR("structlist")); if (strlen(list) > 0) { char *token = strtok(mystrcut_list_ini, ","); while (token != NULL) { zval * token_zval = NULL; ZVAL_NULL(token_zval); ZVAL_STRING(token_zval, token,1); zend_compat_hash_next_index_insert(myextesion_G(mystruct.list), token_zval); } ZEND_INIT_MODULE_GLOBALS(my extension , my_ctor(), NULL) ``` Resulted in this output: when I try to print the values in request code, th values are corrupted. Trying to print the value something like this ``` ZEND_HASH_FOREACH_KEY_VAL(myextension_G(mystruct.list), idx,key, zval) { print("*** Lets print global struct list = %s ****** \n" , Z_STRVAL_P(zval)); } ZEND_HASH_FOREACH_END(); *** Lets print global struct list inside request process = ****** *** Lets print global struct list inside request process = xterm ****** *** Lets print global struct list inside request process = TERM ****** ``` ### PHP Version PHP 8.1.12 ### Operating System Ubuntu 20.0.4

« previous php.bugs (#245027) next »