diff options
Diffstat (limited to 'sapi/phpdbg/phpdbg_wait.c')
-rw-r--r-- | sapi/phpdbg/phpdbg_wait.c | 195 |
1 files changed, 87 insertions, 108 deletions
diff --git a/sapi/phpdbg/phpdbg_wait.c b/sapi/phpdbg/phpdbg_wait.c index 180ae6af3d..a76dda88e4 100644 --- a/sapi/phpdbg/phpdbg_wait.c +++ b/sapi/phpdbg/phpdbg_wait.c @@ -24,19 +24,19 @@ ZEND_EXTERN_MODULE_GLOBALS(phpdbg); static void phpdbg_rebuild_http_globals_array(int type, const char *name TSRMLS_DC) { - zval **zvpp; - if (PG(http_globals)[type]) { - zval_dtor(PG(http_globals)[type]); + zval *zvp; + if (Z_TYPE(PG(http_globals)[type]) != IS_UNDEF) { + zval_dtor(&PG(http_globals)[type]); } - if (zend_hash_find(&EG(symbol_table), name, strlen(name) + 1, (void **) &zvpp) == SUCCESS) { - Z_SET_REFCOUNT_PP(zvpp, 2); - PG(http_globals)[type] = *zvpp; + if ((zvp = zend_hash_str_find(&EG(symbol_table).ht, name, strlen(name)))) { + Z_ADDREF_P(zvp); + PG(http_globals)[type] = *zvp; } } static int phpdbg_dearm_autoglobals(zend_auto_global *auto_global TSRMLS_DC) { - if (auto_global->name_len != sizeof("GLOBALS") - 1 || memcmp(auto_global->name, "GLOBALS", sizeof("GLOBALS") - 1)) { + if (auto_global->name->len != sizeof("GLOBALS") - 1 || memcmp(auto_global->name->val, "GLOBALS", sizeof("GLOBALS") - 1)) { auto_global->armed = 0; } @@ -56,8 +56,8 @@ static int phpdbg_array_data_compare(const void *a, const void *b TSRMLS_DC) { f = *((Bucket **) a); s = *((Bucket **) b); - first = *((zval **) f->pData); - second = *((zval **) s->pData); + first = &f->val; + second = &s->val; if (string_compare_function(&result, first, second TSRMLS_CC) == FAILURE) { return 0; @@ -84,16 +84,15 @@ static void phpdbg_array_intersect_init(phpdbg_intersect_ptr *info, HashTable *h } /* -1 => first array, 0 => both arrays equal, 1 => second array */ -static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval ***ptr) { +static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval **ptr) { int ret; - zval **zvpp[2]; + zval *zvp[2]; int invalid = !info->ht[0] + !info->ht[1]; if (invalid > 0) { invalid = !info->ht[0]; - if (zend_hash_get_current_data_ex(info->ht[invalid], (void **) ptr, &info->pos[invalid]) == FAILURE) { - *ptr = NULL; + if (!(*ptr = zend_hash_get_current_data_ex(info->ht[invalid], &info->pos[invalid]))) { return 0; } @@ -102,23 +101,23 @@ static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval ***ptr) { return invalid ? 1 : -1; } - if (zend_hash_get_current_data_ex(info->ht[0], (void **) &zvpp[0], &info->pos[0]) == FAILURE) { + if (!(zvp[0] = zend_hash_get_current_data_ex(info->ht[0], &info->pos[0]))) { info->ht[0] = NULL; return phpdbg_array_intersect(info, ptr); } - if (zend_hash_get_current_data_ex(info->ht[1], (void **) &zvpp[1], &info->pos[1]) == FAILURE) { + if (!(zvp[1] = zend_hash_get_current_data_ex(info->ht[1], &info->pos[1]))) { info->ht[1] = NULL; return phpdbg_array_intersect(info, ptr); } - ret = zend_binary_zval_strcmp(*zvpp[0], *zvpp[1]); + ret = zend_binary_zval_strcmp(zvp[0], zvp[1]); if (ret <= 0) { - *ptr = zvpp[0]; + *ptr = zvp[0]; zend_hash_move_forward_ex(info->ht[0], &info->pos[0]); } if (ret >= 0) { - *ptr = zvpp[1]; + *ptr = zvp[1]; zend_hash_move_forward_ex(info->ht[1], &info->pos[1]); } @@ -127,12 +126,12 @@ static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval ***ptr) { void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { zval *free_zv = NULL; - zval zv, *zvp = &zv, **zvpp; + zval zv, *zvp; HashTable *ht; php_unserialize_data_t var_hash; PHP_VAR_UNSERIALIZE_INIT(var_hash); - if (!php_var_unserialize(&zvp, (const unsigned char **) &msg, (unsigned char *) msg + len, &var_hash TSRMLS_CC)) { + if (!php_var_unserialize(&zv, (const unsigned char **) &msg, (unsigned char *) msg + len, &var_hash TSRMLS_CC)) { PHP_VAR_UNSERIALIZE_DESTROY(var_hash); phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed serialized was sent to this socket, arborting"); return; @@ -142,14 +141,14 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { ht = Z_ARRVAL(zv); /* Reapply symbol table */ - if (zend_hash_find(ht, "GLOBALS", sizeof("GLOBALS"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_ARRAY) { + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("GLOBALS"))) && Z_TYPE_P(zvp) == IS_ARRAY) { { - zval **srv; - if (zend_hash_find(Z_ARRVAL_PP(zvpp), "_SERVER", sizeof("_SERVER"), (void **) &srv) == SUCCESS && Z_TYPE_PP(srv) == IS_ARRAY) { - zval **script; - if (zend_hash_find(Z_ARRVAL_PP(srv), "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &script) == SUCCESS && Z_TYPE_PP(script) == IS_STRING) { + zval *srv; + if ((srv = zend_hash_str_find(Z_ARRVAL_P(zvp), ZEND_STRL("_SERVER"))) && Z_TYPE_P(srv) == IS_ARRAY) { + zval *script; + if ((script = zend_hash_str_find(Z_ARRVAL_P(srv), ZEND_STRL("SCRIPT_FILENAME"))) && Z_TYPE_P(script) == IS_STRING) { phpdbg_param_t param; - param.str = Z_STRVAL_PP(script); + param.str = Z_STRVAL_P(script); PHPDBG_COMMAND_HANDLER(exec)(¶m TSRMLS_CC); } } @@ -158,8 +157,8 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { PG(auto_globals_jit) = 0; zend_hash_apply(CG(auto_globals), (apply_func_t) phpdbg_dearm_autoglobals TSRMLS_CC); - zend_hash_clean(&EG(symbol_table)); - EG(symbol_table) = *Z_ARRVAL_PP(zvpp); + zend_hash_clean(&EG(symbol_table).ht); + EG(symbol_table) = *Z_ARR_P(zvp); /* Rebuild cookies, env vars etc. from GLOBALS (PG(http_globals)) */ phpdbg_rebuild_http_globals_array(TRACK_VARS_POST, "_POST" TSRMLS_CC); @@ -169,23 +168,21 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { phpdbg_rebuild_http_globals_array(TRACK_VARS_ENV, "_ENV" TSRMLS_CC); phpdbg_rebuild_http_globals_array(TRACK_VARS_FILES, "_FILES" TSRMLS_CC); - Z_ADDREF_PP(zvpp); - free_zv = *zvpp; + Z_ADDREF_P(zvp); + free_zv = zvp; } -#if PHP_VERSION_ID >= 50600 - if (zend_hash_find(ht, "input", sizeof("input"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_STRING) { + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("input"))) && Z_TYPE_P(zvp) == IS_STRING) { if (SG(request_info).request_body) { php_stream_close(SG(request_info).request_body); } SG(request_info).request_body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir)); php_stream_truncate_set_size(SG(request_info).request_body, 0); - php_stream_write(SG(request_info).request_body, Z_STRVAL_PP(zvpp), Z_STRLEN_PP(zvpp)); + php_stream_write(SG(request_info).request_body, Z_STRVAL_P(zvp), Z_STRLEN_P(zvp)); } -#endif - if (zend_hash_find(ht, "cwd", sizeof("cwd"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_STRING) { - if (VCWD_CHDIR(Z_STRVAL_PP(zvpp)) == SUCCESS) { + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("cwd"))) && Z_TYPE_P(zvp) == IS_STRING) { + if (VCWD_CHDIR(Z_STRVAL_P(zvp)) == SUCCESS) { if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentStatFile), strlen(BG(CurrentStatFile)))) { efree(BG(CurrentStatFile)); BG(CurrentStatFile) = NULL; @@ -197,50 +194,46 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { } } - if (zend_hash_find(ht, "sapi_name", sizeof("sapi_name"), (void **) &zvpp) == SUCCESS && (Z_TYPE_PP(zvpp) == IS_STRING || Z_TYPE_PP(zvpp) == IS_NULL)) { + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("sapi_name"))) && (Z_TYPE_P(zvp) == IS_STRING || Z_TYPE_P(zvp) == IS_NULL)) { if (PHPDBG_G(sapi_name_ptr)) { free(PHPDBG_G(sapi_name_ptr)); } - if (Z_TYPE_PP(zvpp) == IS_STRING) { - PHPDBG_G(sapi_name_ptr) = sapi_module.name = strdup(Z_STRVAL_PP(zvpp)); + if (Z_TYPE_P(zvp) == IS_STRING) { + PHPDBG_G(sapi_name_ptr) = sapi_module.name = strdup(Z_STRVAL_P(zvp)); } else { PHPDBG_G(sapi_name_ptr) = sapi_module.name = NULL; } } - if (zend_hash_find(ht, "modules", sizeof("modules"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_ARRAY) { - HashPosition position; + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("modules"))) && Z_TYPE_P(zvp) == IS_ARRAY) { phpdbg_intersect_ptr pos; - zval **module; + zval *module; zend_module_entry *mod; HashTable zv_registry; /* intersect modules, unregister modules loaded "too much", announce not yet registered modules (phpdbg_notice) */ zend_hash_init(&zv_registry, zend_hash_num_elements(&module_registry), 0, ZVAL_PTR_DTOR, 0); - for (zend_hash_internal_pointer_reset_ex(&module_registry, &position); - zend_hash_get_current_data_ex(&module_registry, (void **) &mod, &position) == SUCCESS; - zend_hash_move_forward_ex(&module_registry, &position)) { + ZEND_HASH_FOREACH_PTR(&module_registry, mod) { if (mod->name) { - zval **value = emalloc(sizeof(zval *)); - MAKE_STD_ZVAL(*value); - ZVAL_STRING(*value, mod->name, 1); - zend_hash_next_index_insert(&zv_registry, value, sizeof(zval *), NULL); + zval value; + ZVAL_NEW_STR(&value, zend_string_init(mod->name, strlen(mod->name), 0)); + zend_hash_next_index_insert(&zv_registry, &value); } - } + } ZEND_HASH_FOREACH_END(); - phpdbg_array_intersect_init(&pos, &zv_registry, Z_ARRVAL_PP(zvpp) TSRMLS_CC); + phpdbg_array_intersect_init(&pos, &zv_registry, Z_ARRVAL_P(zvp) TSRMLS_CC); do { int mode = phpdbg_array_intersect(&pos, &module); if (mode < 0) { // loaded module, but not needed - if (strcmp(PHPDBG_NAME, Z_STRVAL_PP(module))) { - zend_hash_del(&module_registry, Z_STRVAL_PP(module), Z_STRLEN_PP(module) + 1); + if (strcmp(PHPDBG_NAME, Z_STRVAL_P(module))) { + zend_hash_del(&module_registry, Z_STR_P(module)); } } else if (mode > 0) { // not loaded module - if (!sapi_module.name || strcmp(sapi_module.name, Z_STRVAL_PP(module))) { - phpdbg_notice("wait", "missingmodule=\"%.*s\"", "The module %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/module/%.*s.so", Z_STRLEN_PP(module), Z_STRVAL_PP(module), Z_STRLEN_PP(module), Z_STRVAL_PP(module)); + if (!sapi_module.name || strcmp(sapi_module.name, Z_STRVAL_P(module))) { + phpdbg_notice("wait", "missingmodule=\"%.*s\"", "The module %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/module/%.*s.so", Z_STRLEN_P(module), Z_STRVAL_P(module), Z_STRLEN_P(module), Z_STRVAL_P(module)); } } } while (module); @@ -248,26 +241,25 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { zend_hash_clean(&zv_registry); } - if (zend_hash_find(ht, "extensions", sizeof("extensions"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_ARRAY) { + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("extensions"))) && Z_TYPE_P(zvp) == IS_ARRAY) { zend_extension *extension; zend_llist_position pos; - HashPosition hpos; - zval **name, key; + zval *name = NULL; + zend_string *strkey; extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos); while (extension) { extension = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &pos); - /* php_serach_array() body should be in some ZEND_API function */ - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(zvpp), &hpos); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(zvpp), (void **) &name, &hpos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_PP(zvpp), &hpos)) { - if (Z_TYPE_PP(name) == IS_STRING && !zend_binary_strcmp(extension->name, strlen(extension->name), Z_STRVAL_PP(name), Z_STRLEN_PP(name))) { + /* php_serach_array() body should be in some ZEND_API function... */ + ZEND_HASH_FOREACH_STR_KEY_PTR(Z_ARRVAL_P(zvp), strkey, name) { + if (Z_TYPE_P(name) == IS_STRING && !zend_binary_strcmp(extension->name, strlen(extension->name), Z_STRVAL_P(name), Z_STRLEN_P(name))) { break; } - } + name = NULL; + } ZEND_HASH_FOREACH_END(); - if (zend_hash_get_current_data_ex(Z_ARRVAL_PP(zvpp), (void **) &zvpp, &hpos) == FAILURE) { + if (name) { /* sigh, breaking the encapsulation, there aren't any functions manipulating the llist at the place of the zend_llist_position */ zend_llist_element *elm = pos; if (elm->prev) { @@ -291,66 +283,53 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { pefree(elm, zend_extensions.persistent); zend_extensions.count--; } else { - zend_hash_get_current_key_zval_ex(Z_ARRVAL_PP(zvpp), &key, &hpos); +/* zend_hash_get_current_key_zval_ex(Z_ARRVAL_PP(zvpp), &key, &hpos); if (Z_TYPE(key) == IS_LONG) { zend_hash_index_del(Z_ARRVAL_PP(zvpp), Z_LVAL(key)); } +*/ + zend_hash_del(Z_ARRVAL_P(zvp), strkey); } + } - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(zvpp), &hpos); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(zvpp), (void **) &name, &hpos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_PP(zvpp), &hpos)) { - phpdbg_notice("wait", "missingextension=\"%.*s\"", "The Zend extension %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/extension.so", Z_STRLEN_PP(name), Z_STRVAL_PP(name)); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zvp), name) { + if (Z_TYPE_P(name) == IS_STRING) { + phpdbg_notice("wait", "missingextension=\"%.*s\"", "The Zend extension %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/extension.so", Z_STRLEN_P(name), Z_STRVAL_P(name)); } - } + } ZEND_HASH_FOREACH_END(); } zend_ini_deactivate(TSRMLS_C); - if (zend_hash_find(ht, "systemini", sizeof("systemini"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_ARRAY) { - HashPosition position; - zval **ini_entry; + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("systemini"))) && Z_TYPE_P(zvp) == IS_ARRAY) { + zval *ini_entry; zend_ini_entry *original_ini; - zval key; - - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(zvpp), &position); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(zvpp), (void**) &ini_entry, &position) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_PP(zvpp), &position)) { - zend_hash_get_current_key_zval_ex(Z_ARRVAL_PP(zvpp), &key, &position); - if (Z_TYPE(key) == IS_STRING) { - if (Z_TYPE_PP(ini_entry) == IS_STRING) { - if (zend_hash_find(EG(ini_directives), Z_STRVAL(key), Z_STRLEN(key) + 1, (void **) &original_ini) == SUCCESS) { - if (!original_ini->on_modify || original_ini->on_modify(original_ini, Z_STRVAL_PP(ini_entry), Z_STRLEN_PP(ini_entry), original_ini->mh_arg1, original_ini->mh_arg2, original_ini->mh_arg3, ZEND_INI_STAGE_ACTIVATE TSRMLS_CC) == SUCCESS) { - if (original_ini->modified && original_ini->orig_value != original_ini->value) { - efree(original_ini->value); - } - original_ini->value = Z_STRVAL_PP(ini_entry); - original_ini->value_length = Z_STRLEN_PP(ini_entry); - Z_TYPE_PP(ini_entry) = IS_NULL; /* don't free the value */ + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) { + if (key && Z_TYPE_P(ini_entry) == IS_STRING) { + if ((original_ini = zend_hash_find_ptr(EG(ini_directives), key))) { + if (!original_ini->on_modify || original_ini->on_modify(original_ini, Z_STR_P(ini_entry), original_ini->mh_arg1, original_ini->mh_arg2, original_ini->mh_arg3, ZEND_INI_STAGE_ACTIVATE TSRMLS_CC) == SUCCESS) { + if (original_ini->modified && original_ini->orig_value != original_ini->value) { + efree(original_ini->value); } + original_ini->value = Z_STR_P(ini_entry); + Z_ADDREF_P(ini_entry); /* don't free the string */ } } - efree(Z_STRVAL(key)); } - } + } ZEND_HASH_FOREACH_END(); } - if (zend_hash_find(ht, "userini", sizeof("userini"), (void **) &zvpp) == SUCCESS && Z_TYPE_PP(zvpp) == IS_ARRAY) { - HashPosition position; - zval **ini_entry; - zval key; - - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(zvpp), &position); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(zvpp), (void**) &ini_entry, &position) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_PP(zvpp), &position)) { - zend_hash_get_current_key_zval_ex(Z_ARRVAL_PP(zvpp), &key, &position); - if (Z_TYPE(key) == IS_STRING) { - if (Z_TYPE_PP(ini_entry) == IS_STRING) { - zend_alter_ini_entry_ex(Z_STRVAL(key), Z_STRLEN(key) + 1, Z_STRVAL_PP(ini_entry), Z_STRLEN_PP(ini_entry), ZEND_INI_PERDIR, ZEND_INI_STAGE_HTACCESS, 1 TSRMLS_CC); - } - efree(Z_STRVAL(key)); + if ((zvp = zend_hash_str_find(ht, ZEND_STRL("userini"))) && Z_TYPE_P(zvp) == IS_ARRAY) { + zval *ini_entry; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) { + if (key && Z_TYPE_P(ini_entry) == IS_STRING) { + zend_alter_ini_entry_ex(key, Z_STR_P(ini_entry), ZEND_INI_PERDIR, ZEND_INI_STAGE_HTACCESS, 1 TSRMLS_CC); } - } + } ZEND_HASH_FOREACH_END(); } zval_dtor(&zv); @@ -365,7 +344,7 @@ void phpdbg_webdata_decompress(char *msg, int len TSRMLS_DC) { PHPDBG_COMMAND(wait) /* {{{ */ { -#if PHPDBG_IN_DEV +#ifndef PHP_WIN32 struct sockaddr_un local, remote; int rlen, sr, sl; unlink(PHPDBG_G(socket_path)); |