From 6487590b4fd55dddd59b43f1fcf2ebd8d56f20ac Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 20 Sep 2017 10:51:22 +0200 Subject: Add travis --- src/sp_utils.c | 55 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'src/sp_utils.c') diff --git a/src/sp_utils.c b/src/sp_utils.c index 087f431..56512df 100644 --- a/src/sp_utils.c +++ b/src/sp_utils.c @@ -201,7 +201,7 @@ bool sp_match_value(const char* value, const char* to_match, const pcre* rx) { } } else if (rx) { int substrvec[30]; - int ret = pcre_exec(rx, NULL, value, strlen(value), 0, 0, substrvec, 30); + int ret = sp_pcre_exec(rx, NULL, value, strlen(value), 0, 0, substrvec, 30); if (ret < 0) { if (ret != PCRE_ERROR_NOMATCH) { @@ -223,14 +223,14 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name, const int sim = config_node->simulation; if (arg_name) { if (alias) { - sp_log_msg("disabled_function", sim?LOG_NOTICE:LOG_DROP, + sp_log_msg("disabled_function", sim?SP_LOG_NOTICE:SP_LOG_DROP, "The call to the function '%s' in %s:%d has been disabled, " "because its argument '%s' content (%s) matched the rule '%s'.", path, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), arg_name, arg_value?arg_value:"?", alias); } else { - sp_log_msg("disabled_function", sim?LOG_NOTICE:LOG_DROP, + sp_log_msg("disabled_function", sim?SP_LOG_NOTICE:SP_LOG_DROP, "The call to the function '%s' in %s:%d has been disabled, " "because its argument '%s' content (%s) matched a rule.", path, zend_get_executed_filename(TSRMLS_C), @@ -239,13 +239,13 @@ void sp_log_disable(const char* restrict path, const char* restrict arg_name, } } else { if (alias) { - sp_log_msg("disabled_function", sim?LOG_NOTICE:LOG_DROP, + sp_log_msg("disabled_function", sim?SP_LOG_NOTICE:SP_LOG_DROP, "The call to the function '%s' in %s:%d has been disabled, " "because of the the rule '%s'.",path, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), alias); } else { - sp_log_msg("disabled_function", sim?LOG_NOTICE:LOG_DROP, + sp_log_msg("disabled_function", sim?SP_LOG_NOTICE:SP_LOG_DROP, "The call to the function '%s' in %s:%d has been disabled.", path, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); @@ -263,13 +263,13 @@ void sp_log_disable_ret(const char* restrict path, const char* alias = config_node->alias; const int sim = config_node->simulation; if (alias) { - sp_log_msg("disabled_function", sim?LOG_NOTICE:LOG_DROP, + sp_log_msg("disabled_function", sim?SP_LOG_NOTICE:SP_LOG_DROP, "The execution has been aborted in %s:%d, " "because the function '%s' returned '%s', which matched the rule '%s'.", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), path, ret_value?ret_value:"?", alias); } else { - sp_log_msg("disabled_function", sim?LOG_NOTICE:LOG_DROP, + sp_log_msg("disabled_function", sim?SP_LOG_NOTICE:SP_LOG_DROP, "The execution has been aborted in %s:%d, " "because the return value (%s) of the function '%s' matched a rule.", zend_get_executed_filename(TSRMLS_C), @@ -349,7 +349,7 @@ zend_always_inline char* sp_getenv(char* var) { zend_always_inline int is_regexp_matching(const pcre* regexp, const char* str) { int vec[30]; - int ret = pcre_exec(regexp, NULL, str, strlen(str), 0, 0, vec, sizeof(vec)); + int ret = sp_pcre_exec(regexp, NULL, str, strlen(str), 0, 0, vec, sizeof(vec)); if (ret < 0) { if (ret != PCRE_ERROR_NOMATCH) { sp_log_err("regexp", "Something went wrong with a regexp."); @@ -367,22 +367,14 @@ int hook_function(const char* original_name, HashTable* hook_table, /* The `mb` module likes to hook functions, like strlen->mb_strlen, * so we have to hook both of them. */ - if (0 == strncmp(original_name, "mb_", 3)) { - CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; - if (zend_hash_str_find(ht, - VAR_AND_LEN(original_name + 3))) { - hook_function(original_name + 3, hook_table, new_function, hook_execution_table); - } - } else { // TODO this can be moved somewhere else to gain some marginal perfs - CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; - char* mb_name = pecalloc(strlen(original_name) + 3 + 1, 1, 0); - memcpy(mb_name, "mb_", 3); - memcpy(mb_name + 3, VAR_AND_LEN(original_name)); - if (zend_hash_str_find(CG(function_table), VAR_AND_LEN(mb_name))) { - hook_function(mb_name, hook_table, new_function, hook_execution_table); + + if ((func = zend_hash_str_find_ptr(ht, + VAR_AND_LEN(original_name)))) { + if (func->handler == new_function) { + return SUCCESS; } } - + if ((func = zend_hash_str_find_ptr(CG(function_table), VAR_AND_LEN(original_name)))) { if (func->handler == new_function) { @@ -397,6 +389,23 @@ int hook_function(const char* original_name, HashTable* hook_table, func->handler = new_function; } } + + if (0 == strncmp(original_name, "mb_", 3)) { + CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; + if (zend_hash_str_find(ht, + VAR_AND_LEN(original_name + 3))) { + hook_function(original_name + 3, hook_table, new_function, hook_execution_table); + } + } else { // TODO this can be moved somewhere else to gain some marginal perfs + CG(compiler_options) |= ZEND_COMPILE_NO_BUILTIN_STRLEN; + char* mb_name = pecalloc(strlen(original_name) + 3 + 1, 1, 0); + memcpy(mb_name, "mb_", 3); + memcpy(mb_name + 3, VAR_AND_LEN(original_name)); + if (zend_hash_str_find(CG(function_table), VAR_AND_LEN(mb_name))) { + hook_function(mb_name, hook_table, new_function, hook_execution_table); + } + } + return SUCCESS; } @@ -409,7 +418,7 @@ int hook_regexp(const pcre* regexp, HashTable* hook_table, ZEND_HASH_FOREACH_STR_KEY(ht, key) { if (key) { int vec[30]; - int ret = pcre_exec(regexp, NULL, key->val, key->len, 0, 0, vec, 30); + int ret = sp_pcre_exec(regexp, NULL, key->val, key->len, 0, 0, vec, 30); if (ret < 0) { /* Error or no match*/ if (PCRE_ERROR_NOMATCH != ret) { sp_log_err("pcre", "Runtime error with pcre, error code: %d", ret); -- cgit v1.3