Use HashTable.u.flags instead of HashTable.arHash to check if HashTable is properly initialized

This commit is contained in:
Dmitry Stogov 2014-12-30 00:14:13 +03:00
parent ee7decb7ff
commit 6b20895c21
7 changed files with 42 additions and 42 deletions

View File

@ -44,9 +44,9 @@ static int phar_dir_close(php_stream *stream, int close_handle) /* {{{ */
{
HashTable *data = (HashTable *)stream->abstract;
if (data && data->arHash) {
if (data && data->u.flags) {
zend_hash_destroy(data);
data->arHash = 0;
data->u.flags = 0;
FREE_HASHTABLE(data);
stream->abstract = NULL;
}
@ -361,7 +361,7 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
return ret;
}
if (!phar->manifest.arHash) {
if (!phar->manifest.u.flags) {
php_url_free(resource);
return NULL;
}

View File

@ -33,8 +33,8 @@ PHAR_FUNC(phar_opendir) /* {{{ */
goto skip_phar;
}
if ((PHAR_GLOBALS->phar_fname_map.arHash && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.arHash) {
if ((PHAR_GLOBALS->phar_fname_map.u.flags && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.u.flags) {
goto skip_phar;
}
@ -106,8 +106,8 @@ PHAR_FUNC(phar_file_get_contents) /* {{{ */
goto skip_phar;
}
if ((PHAR_GLOBALS->phar_fname_map.arHash && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.arHash) {
if ((PHAR_GLOBALS->phar_fname_map.u.flags && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.u.flags) {
goto skip_phar;
}
@ -234,8 +234,8 @@ PHAR_FUNC(phar_readfile) /* {{{ */
goto skip_phar;
}
if ((PHAR_GLOBALS->phar_fname_map.arHash && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.arHash) {
if ((PHAR_GLOBALS->phar_fname_map.u.flags && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.u.flags) {
goto skip_phar;
}
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "p|br!", &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) {
@ -329,8 +329,8 @@ PHAR_FUNC(phar_fopen) /* {{{ */
goto skip_phar;
}
if ((PHAR_GLOBALS->phar_fname_map.arHash && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.arHash) {
if ((PHAR_GLOBALS->phar_fname_map.u.flags && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.u.flags) {
/* no need to check, include_path not even specified in fopen/ no active phars */
goto skip_phar;
}
@ -895,8 +895,8 @@ PHAR_FUNC(phar_is_file) /* {{{ */
goto skip_phar;
}
if ((PHAR_GLOBALS->phar_fname_map.arHash && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.arHash) {
if ((PHAR_GLOBALS->phar_fname_map.u.flags && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.u.flags) {
goto skip_phar;
}
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) {
@ -962,8 +962,8 @@ PHAR_FUNC(phar_is_link) /* {{{ */
goto skip_phar;
}
if ((PHAR_GLOBALS->phar_fname_map.arHash && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.arHash) {
if ((PHAR_GLOBALS->phar_fname_map.u.flags && !zend_hash_num_elements(&(PHAR_GLOBALS->phar_fname_map)))
&& !cached_phars.u.flags) {
goto skip_phar;
}
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) {

View File

@ -82,7 +82,7 @@ ZEND_INI_MH(phar_ini_modify_handler) /* {{{ */
if (entry->name->len == sizeof("phar.readonly")-1) {
PHAR_G(readonly) = ini;
if (PHAR_GLOBALS->request_init && PHAR_GLOBALS->phar_fname_map.arHash) {
if (PHAR_GLOBALS->request_init && PHAR_GLOBALS->phar_fname_map.u.flags) {
zend_hash_apply_with_argument(&(PHAR_GLOBALS->phar_fname_map), phar_set_writeable_bit, (void *)&ini);
}
} else {
@ -146,9 +146,9 @@ finish_error:
PHAR_GLOBALS->manifest_cached = 0;
efree(tmp);
zend_hash_destroy(&(PHAR_G(phar_fname_map)));
PHAR_GLOBALS->phar_fname_map.arHash = 0;
PHAR_GLOBALS->phar_fname_map.u.flags = 0;
zend_hash_destroy(&(PHAR_G(phar_alias_map)));
PHAR_GLOBALS->phar_alias_map.arHash = 0;
PHAR_GLOBALS->phar_alias_map.u.flags = 0;
zend_hash_destroy(&cached_phars);
zend_hash_destroy(&cached_alias);
zend_hash_graceful_reverse_destroy(&EG(regular_list));
@ -173,8 +173,8 @@ finish_error:
zend_hash_destroy(&cached_alias);
cached_phars = PHAR_GLOBALS->phar_fname_map;
cached_alias = PHAR_GLOBALS->phar_alias_map;
PHAR_GLOBALS->phar_fname_map.arHash = 0;
PHAR_GLOBALS->phar_alias_map.arHash = 0;
PHAR_GLOBALS->phar_fname_map.u.flags = 0;
PHAR_GLOBALS->phar_alias_map.u.flags = 0;
zend_hash_graceful_reverse_destroy(&EG(regular_list));
memset(&EG(regular_list), 0, sizeof(HashTable));
efree(tmp);
@ -220,19 +220,19 @@ void phar_destroy_phar_data(phar_archive_data *phar) /* {{{ */
phar->signature = NULL;
}
if (phar->manifest.arHash) {
if (phar->manifest.u.flags) {
zend_hash_destroy(&phar->manifest);
phar->manifest.arHash = NULL;
phar->manifest.u.flags = 0;
}
if (phar->mounted_dirs.arHash) {
if (phar->mounted_dirs.u.flags) {
zend_hash_destroy(&phar->mounted_dirs);
phar->mounted_dirs.arHash = NULL;
phar->mounted_dirs.u.flags = 0;
}
if (phar->virtual_dirs.arHash) {
if (phar->virtual_dirs.u.flags) {
zend_hash_destroy(&phar->virtual_dirs);
phar->virtual_dirs.arHash = NULL;
phar->virtual_dirs.u.flags = 0;
}
if (Z_TYPE(phar->metadata) != IS_UNDEF) {
@ -3487,11 +3487,11 @@ PHP_RSHUTDOWN_FUNCTION(phar) /* {{{ */
{
phar_release_functions();
zend_hash_destroy(&(PHAR_GLOBALS->phar_alias_map));
PHAR_GLOBALS->phar_alias_map.arHash = NULL;
PHAR_GLOBALS->phar_alias_map.u.flags = 0;
zend_hash_destroy(&(PHAR_GLOBALS->phar_fname_map));
PHAR_GLOBALS->phar_fname_map.arHash = NULL;
PHAR_GLOBALS->phar_fname_map.u.flags = 0;
zend_hash_destroy(&(PHAR_GLOBALS->phar_persist_map));
PHAR_GLOBALS->phar_persist_map.arHash = NULL;
PHAR_GLOBALS->phar_persist_map.u.flags = 0;
PHAR_GLOBALS->phar_SERVER_mung_list = 0;
if (PHAR_GLOBALS->cached_fp) {

View File

@ -517,7 +517,7 @@ carry_on:
}
return;
} else if (PHAR_GLOBALS->phar_fname_map.arHash && NULL != (pphar = zend_hash_str_find_ptr(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len))) {
} else if (PHAR_GLOBALS->phar_fname_map.u.flags && NULL != (pphar = zend_hash_str_find_ptr(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len))) {
goto carry_on;
} else if (PHAR_G(manifest_cached) && NULL != (pphar = zend_hash_str_find_ptr(&cached_phars, fname, fname_len))) {
if (SUCCESS == phar_copy_on_write(&pphar)) {

View File

@ -103,7 +103,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const
if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) {
phar_archive_data *pphar = NULL, *phar;
if (PHAR_GLOBALS->request_init && PHAR_GLOBALS->phar_fname_map.arHash && NULL == (pphar = zend_hash_str_find_ptr(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len))) {
if (PHAR_GLOBALS->request_init && PHAR_GLOBALS->phar_fname_map.u.flags && NULL == (pphar = zend_hash_str_find_ptr(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len))) {
pphar = NULL;
}
if (PHAR_G(readonly) && (!pphar || !pphar->is_data)) {
@ -608,7 +608,7 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
php_url_free(resource);
return SUCCESS;
}
if (!phar->manifest.arHash) {
if (!phar->manifest.u.flags) {
php_url_free(resource);
return FAILURE;
}
@ -625,7 +625,7 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
return SUCCESS;
}
/* check for mounted directories */
if (phar->mounted_dirs.arHash && zend_hash_num_elements(&phar->mounted_dirs)) {
if (phar->mounted_dirs.u.flags && zend_hash_num_elements(&phar->mounted_dirs)) {
zend_string *str_key;
ZEND_HASH_FOREACH_STR_KEY(&phar->mounted_dirs, str_key) {

View File

@ -925,7 +925,7 @@ phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry,
PHP_PHAR_API int phar_resolve_alias(char *alias, int alias_len, char **filename, int *filename_len) /* {{{ */ {
phar_archive_data *fd_ptr;
if (PHAR_GLOBALS->phar_alias_map.arHash
if (PHAR_GLOBALS->phar_alias_map.u.flags
&& NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len))) {
*filename = fd_ptr->fname;
*filename_len = fd_ptr->fname_len;
@ -1249,7 +1249,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
return NULL;
}
if (!phar->manifest.arHash) {
if (!phar->manifest.u.flags) {
return NULL;
}
@ -1294,7 +1294,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
}
}
if (phar->mounted_dirs.arHash && zend_hash_num_elements(&phar->mounted_dirs)) {
if (phar->mounted_dirs.u.flags && zend_hash_num_elements(&phar->mounted_dirs)) {
zend_string *str_key;
ZEND_HASH_FOREACH_STR_KEY(&phar->mounted_dirs, str_key) {

View File

@ -293,11 +293,11 @@ foundit:
entry.is_persistent = mydata->is_persistent;
#define PHAR_ZIP_FAIL_FREE(errmsg, save) \
zend_hash_destroy(&mydata->manifest); \
mydata->manifest.arHash = 0; \
mydata->manifest.u.flags = 0; \
zend_hash_destroy(&mydata->mounted_dirs); \
mydata->mounted_dirs.arHash = 0; \
mydata->mounted_dirs.u.flags = 0; \
zend_hash_destroy(&mydata->virtual_dirs); \
mydata->virtual_dirs.arHash = 0; \
mydata->virtual_dirs.u.flags = 0; \
php_stream_close(fp); \
zval_dtor(&mydata->metadata); \
if (mydata->signature) { \
@ -315,11 +315,11 @@ foundit:
return FAILURE;
#define PHAR_ZIP_FAIL(errmsg) \
zend_hash_destroy(&mydata->manifest); \
mydata->manifest.arHash = 0; \
mydata->manifest.u.flags = 0; \
zend_hash_destroy(&mydata->mounted_dirs); \
mydata->mounted_dirs.arHash = 0; \
mydata->mounted_dirs.u.flags = 0; \
zend_hash_destroy(&mydata->virtual_dirs); \
mydata->virtual_dirs.arHash = 0; \
mydata->virtual_dirs.u.flags = 0; \
php_stream_close(fp); \
zval_dtor(&mydata->metadata); \
if (mydata->signature) { \