From 57b345f16ccad6e5b273c58e819ca5adefdcbf72 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 20 Mar 2022 18:43:35 +0100 Subject: Fix compilation on PHP<7.2 --- src/sp_config_keywords.c | 2 +- src/sp_php_compat.h | 2 +- src/sp_unserialize.c | 4 ++++ src/tests/broken_configuration/encrypt_regexp_cookies_bad_regexp.phpt | 4 +--- src/tests/disable_function/disabled_functions_shell_exec_closure.phpt | 1 + 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 9a9b608..f7be731 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -321,7 +321,7 @@ SP_PARSE_FN(parse_disabled_functions) { goto out; } if (df->filename && (*ZSTR_VAL(df->filename) != '/') && - (0 != strncmp(ZSTR_VAL(df->filename), ZEND_STRL("phar://")))) { + (0 != strncmp(ZSTR_VAL(df->filename), "phar://", sizeof("phar://")))) { sp_log_err("config", "Invalid configuration line: 'sp.disabled_functions': '.filename' must be an absolute path or a phar archive on line %zu", parsed_rule->lineno); goto out; } diff --git a/src/sp_php_compat.h b/src/sp_php_compat.h index 04914b4..2334f62 100644 --- a/src/sp_php_compat.h +++ b/src/sp_php_compat.h @@ -111,7 +111,7 @@ static inline void php_hash_string_xor_char(unsigned char *out, const unsigned c static inline void php_hash_hmac_prep_key(unsigned char *K, const php_hash_ops *ops, void *context, const unsigned char *key, const size_t key_len) { memset(K, 0, ops->block_size); - if (key_len > ops->block_size) { + if (key_len > (size_t)ops->block_size) { /* Reduce the key first */ #if PHP_VERSION_ID < 80100 ops->hash_init(context); diff --git a/src/sp_unserialize.c b/src/sp_unserialize.c index c2173d3..2e7c173 100644 --- a/src/sp_unserialize.c +++ b/src/sp_unserialize.c @@ -18,7 +18,11 @@ static zend_string *sp_do_hash_hmac_sha256(char *data, size_t data_len, char *ke zend_string_release_ex(algo, 0); #endif +#if PHP_VERSION_ID < 70200 + if (!ops) { +#else if (!ops || !ops->is_crypto) { +#endif sp_log_err("hmac", "unsupported hash algorithm: sha256"); return NULL; } diff --git a/src/tests/broken_configuration/encrypt_regexp_cookies_bad_regexp.phpt b/src/tests/broken_configuration/encrypt_regexp_cookies_bad_regexp.phpt index f660f28..2b9f709 100644 --- a/src/tests/broken_configuration/encrypt_regexp_cookies_bad_regexp.phpt +++ b/src/tests/broken_configuration/encrypt_regexp_cookies_bad_regexp.phpt @@ -15,6 +15,4 @@ EOF; --FILE-- --EXPECTF-- -Fatal error: [snuffleupagus][127.0.0.1][config][log] Invalid configuration file in Unknown on line 0 -%A -Fatal error: [snuffleupagus][127.0.0.1][config][log] Invalid regexp '^super_co[a-z+$' for '.name_r()' on line 2 in Unknown on line 0 +%AFatal error: [snuffleupagus][127.0.0.1][config][log] Invalid regexp '^super_co[a-z+$' for '.name_r()' on line 2 in Unknown on line 0 diff --git a/src/tests/disable_function/disabled_functions_shell_exec_closure.phpt b/src/tests/disable_function/disabled_functions_shell_exec_closure.phpt index fd9343b..ee1635c 100644 --- a/src/tests/disable_function/disabled_functions_shell_exec_closure.phpt +++ b/src/tests/disable_function/disabled_functions_shell_exec_closure.phpt @@ -2,6 +2,7 @@ Disable functions - shell_exec via closure --SKIPIF-- + --INI-- sp.configuration_file={PWD}/config/disabled_functions_extra.ini --FILE-- -- cgit v1.3