From a48297dfc1144931e18073a87ed83ea337e3d37a Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 23 Feb 2019 00:03:14 +0000 Subject: Add php8 to travis and fix php7.4 - Use clang-format on the code - Improve portability wrt. php8 - Fix php7.4 compatibility. See https://dustri.org/b/fixing-snuffleupagus-sloppy-comparison-on-array_keys-for-php74.html for a detailed writeup--- src/sp_config_keywords.c | 5 +++-- src/sp_disabled_functions.c | 7 ++----- src/sp_session.c | 4 ++-- src/sp_sloppy.c | 21 +++++++++++---------- src/sp_utils.c | 2 ++ 5 files changed, 20 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 760961a..a9c71d4 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -41,8 +41,9 @@ int parse_session(char *line) { return ret; } -#if ( !HAVE_PHP_SESSION || defined(COMPILE_DL_SESSION) ) - sp_log_err("config", +#if (!HAVE_PHP_SESSION || defined(COMPILE_DL_SESSION)) + sp_log_err( + "config", "You're trying to use the session cookie encryption feature " "on line %zu without having session support statically built into PHP. " "This isn't supported, see " diff --git a/src/sp_disabled_functions.c b/src/sp_disabled_functions.c index bb22f71..0f42f8f 100644 --- a/src/sp_disabled_functions.c +++ b/src/sp_disabled_functions.c @@ -371,11 +371,8 @@ static void should_disable(zend_execute_data* execute_data, } if (config_node->r_value || config_node->value) { - if (check_is_builtin_name(config_node) && - !config_node->var && - !config_node->key && - !config_node->r_key && - !config_node->param && + if (check_is_builtin_name(config_node) && !config_node->var && + !config_node->key && !config_node->r_key && !config_node->param && !config_node->r_param) { if (false == is_param_matching(execute_data, config_node, builtin_param, &arg_name, builtin_param_name, diff --git a/src/sp_session.c b/src/sp_session.c index c708ea0..0f45f9b 100644 --- a/src/sp_session.c +++ b/src/sp_session.c @@ -3,7 +3,7 @@ ZEND_DECLARE_MODULE_GLOBALS(snuffleupagus) -#if ( HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION) ) +#if (HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)) #ifdef ZTS static ts_rsrc_id session_globals_id = 0; @@ -165,6 +165,6 @@ void hook_session() { #else -void hook_session() { } +void hook_session() {} #endif // HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION) diff --git a/src/sp_sloppy.c b/src/sp_sloppy.c index d510181..8c36822 100644 --- a/src/sp_sloppy.c +++ b/src/sp_sloppy.c @@ -43,20 +43,21 @@ static void array_handler(INTERNAL_FUNCTION_PARAMETERS, const char* name, zval func_name; zval params[3]; zval *value, *array = NULL; - zend_bool strict = 1; + zend_bool strict = 0; + uint32_t nb_params = ZEND_NUM_ARGS(); - memset(¶ms, 0, sizeof(params)); - - zend_parse_parameters(ZEND_NUM_ARGS(), spec, &value, &array, &strict); + zend_parse_parameters(nb_params, spec, &value, &array, &strict); ZVAL_COPY(¶ms[0], value); + ZVAL_BOOL(¶ms[2], 1); // we want to always have strict mode enabled + if (array) { ZVAL_COPY(¶ms[1], array); - ZVAL_BOOL(¶ms[2], 1); + // Lie about the number of parameters, + // since we are always passing strict = 1 + nb_params = 3; } else { - // if there is no array as parameter, don't set strict mode. - // check php's implementation for details. - ZVAL_BOOL(¶ms[2], 0); + ZVAL_NULL(¶ms[1]); } ZVAL_STRING(&func_name, name); @@ -67,8 +68,8 @@ static void array_handler(INTERNAL_FUNCTION_PARAMETERS, const char* name, zend_hash_str_find_ptr(CG(function_table), name, size); func->handler = handler; - call_user_function(CG(function_table), NULL, &func_name, return_value, 3, - params); + call_user_function(CG(function_table), NULL, &func_name, return_value, + nb_params, params); func->handler = orig_handler; } diff --git a/src/sp_utils.c b/src/sp_utils.c index acac310..1231bee 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c @@ -344,7 +344,9 @@ int hook_function(const char* original_name, HashTable* hook_table, } } +#if PHP_VERSION_ID < 80000 CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; +#endif if (0 == strncmp(original_name, "mb_", 3) && !CG(multibyte)) { if (zend_hash_str_find(CG(function_table), -- cgit v1.3