From 9c5ea420aca534bb9ef5bab20162c2ccf73a4274 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Thu, 5 Apr 2007 19:49:42 +0000 Subject: [PATCH] - MFH zend_info_call_*() stuff, fixes coverity issue #328, noticed by tony --- Zend/zend_API.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index c6a3f87f17..1524031dee 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2377,19 +2377,41 @@ ZEND_API int zend_fcall_info_init(zval *callable, zend_fcall_info *fci, zend_fca } -ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC) +ZEND_API void zend_fcall_info_args_clear(zend_fcall_info *fci, int free_mem) { - HashPosition pos; - zval **arg, ***params; - if (fci->params) { while (fci->param_count) { zval_ptr_dtor(fci->params[--fci->param_count]); } - efree(fci->params); + if (free_mem) { + efree(fci->params); + fci->params = NULL; + } } - fci->params = NULL; fci->param_count = 0; +} + +ZEND_API void zend_fcall_info_args_save(zend_fcall_info *fci, int *param_count, zval ****params) +{ + *param_count = fci->param_count; + *params = fci->params; + fci->param_count = 0; + fci->params = NULL; +} + +ZEND_API void zend_fcall_info_args_restore(zend_fcall_info *fci, int param_count, zval ***params) +{ + zend_fcall_info_args_clear(fci, 1); + fci->param_count = param_count; + fci->params = params; +} + +ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC) +{ + HashPosition pos; + zval **arg, ***params; + + zend_fcall_info_args_clear(fci, !args); if (!args) { return SUCCESS; @@ -2403,7 +2425,6 @@ ZEND_API int zend_fcall_info_args(zend_fcall_info *fci, zval *args TSRMLS_DC) fci->params = params = (zval***)safe_emalloc(sizeof(zval**), fci->param_count, 0); zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(args), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(args), (void **) &arg, &pos) == SUCCESS) { *params++ = arg; (*arg)->refcount++; @@ -2420,8 +2441,7 @@ ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *f fci->retval_ptr_ptr = retval_ptr_ptr ? retval_ptr_ptr : &retval; if (args) { - org_params = fci->params; - org_count = fci->param_count; + zend_fcall_info_args_save(fci, &org_count, &org_params); zend_fcall_info_args(fci, args TSRMLS_CC); } result = zend_call_function(fci, fcc TSRMLS_CC); @@ -2430,9 +2450,7 @@ ZEND_API int zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_cache *f zval_ptr_dtor(&retval); } if (args) { - zend_fcall_info_args(fci, NULL TSRMLS_CC); - fci->params = org_params; - fci->param_count = org_count; + zend_fcall_info_args_restore(fci, org_count, org_params); } return result; } -- 2.50.1