From: Zeev Suraski Date: Wed, 8 Aug 2001 20:05:37 +0000 (+0000) Subject: Implement import_request_variables() X-Git-Tag: BEFORE_EXP_MERGE~82 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f47962c7c09bb9c9bb7a7acc767b45dbd1b6489d;p=php Implement import_request_variables() --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 6093f530b7..721575165b 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -371,6 +371,7 @@ function_entry basic_functions[] = { PHP_FE(is_object, NULL) PHP_FE(is_scalar, NULL) PHP_FE(is_callable, third_arg_force_ref) + PHP_FE(import_request_variables, NULL) PHP_FE(error_log, NULL) PHP_FE(call_user_func, NULL) @@ -2612,6 +2613,90 @@ PHP_FUNCTION(is_callable) /* }}} */ +static int copy_request_variable(void *pDest, int num_args, va_list args, zend_hash_key *hash_key) +{ + char *prefix, *new_key; + uint prefix_len, new_key_len; + zval **var = (zval **) pDest; + TSRMLS_FETCH(); + + if (num_args!=2) { + return 0; + } + + prefix = va_arg(args, char *); + prefix_len = va_arg(args, uint); + + new_key_len = prefix_len + hash_key->nKeyLength; + new_key = (char *) emalloc(new_key_len); + + memcpy(new_key, prefix, prefix_len); + memcpy(new_key+prefix_len, hash_key->arKey, hash_key->nKeyLength); + + ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), new_key, new_key_len, *var, 0, 1); + + efree(new_key); + + return 0; +} + + +/* {{{ proto bool import_request_variables(string types, string prefix) + Import GET/POST/Cookie variables into the global scope */ +PHP_FUNCTION(import_request_variables) +{ + zval **z_types, **z_prefix; + char *types, *prefix; + uint prefix_len; + char *p; + + switch (ZEND_NUM_ARGS()) { + case 1: + if (zend_get_parameters_ex(1, &z_types)==FAILURE) { + RETURN_FALSE; + } + prefix = ""; + prefix_len = 0; + break; + case 2: + if (zend_get_parameters_ex(2, &z_types, &z_prefix)==FAILURE) { + RETURN_FALSE; + } + convert_to_string_ex(z_prefix); + prefix = Z_STRVAL_PP(z_prefix); + prefix_len = Z_STRLEN_PP(z_prefix); + break; + default: + ZEND_WRONG_PARAM_COUNT(); + } + + if (prefix_len==0) { + zend_error(E_NOTICE, "No prefix specified in %s() - possible security hazard", get_active_function_name(TSRMLS_C)); + } + + convert_to_string_ex(z_types); + types = Z_STRVAL_PP(z_types); + + for (p=types; p && *p; p++) { + switch (*p) { + case 'g': + case 'G': + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + break; + case 'p': + case 'P': + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_FILES]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + break; + case 'c': + case 'C': + zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); + break; + } + } +} + + /* * Local variables: * tab-width: 4 diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index e22a604eeb..6001628b66 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -77,6 +77,7 @@ PHP_FUNCTION(is_array); PHP_FUNCTION(is_object); PHP_FUNCTION(is_scalar); PHP_FUNCTION(is_callable); +PHP_FUNCTION(import_request_variables); PHP_FUNCTION(error_log); diff --git a/main/main.c b/main/main.c index 7b3252ce7e..620ba9bc58 100644 --- a/main/main.c +++ b/main/main.c @@ -105,6 +105,7 @@ static int short_track_vars_names_length[] = { sizeof("_FILES") }; +#define NUM_TRACK_VARS (sizeof(short_track_vars_names_length)/sizeof(int)) #define SAFE_FILENAME(f) ((f)?(f):"-") @@ -718,6 +719,15 @@ void php_request_shutdown(void *dummy) if (PG(modules_activated)) { zend_deactivate_modules(TSRMLS_C); } + + zend_try { + int i; + + for (i=0; irefcount++; zend_hash_update(&EG(symbol_table), short_track_vars_names[i], short_track_vars_names_length[i], &PG(http_globals)[i], sizeof(zval *), NULL); + PG(http_globals)[i]->refcount++; } {