mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Refactoring conditional directives for if wrappers, alternative if statements and incomplete if conditions.
This commit is contained in:
committed by
Felipe Zimmerle
parent
c373256d46
commit
3a7fdf8fc0
@@ -755,6 +755,9 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
|
|||||||
char *rid = NULL;
|
char *rid = NULL;
|
||||||
msre_rule *rule = NULL;
|
msre_rule *rule = NULL;
|
||||||
extern msc_engine *modsecurity;
|
extern msc_engine *modsecurity;
|
||||||
|
int type_with_lua = 1;
|
||||||
|
int type_rule;
|
||||||
|
int rule_actionset;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
#ifdef DEBUG_CONF
|
#ifdef DEBUG_CONF
|
||||||
@@ -787,25 +790,25 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Rules must have uniq ID */
|
/* Rules must have uniq ID */
|
||||||
if (
|
type_rule = (dcfg->tmp_chain_starter == NULL);
|
||||||
#if defined(WITH_LUA)
|
#if defined(WITH_LUA)
|
||||||
type != RULE_TYPE_LUA &&
|
type_rule = (type != RULE_TYPE_LUA && type_rule);
|
||||||
#endif
|
#endif
|
||||||
(dcfg->tmp_chain_starter == NULL))
|
if (type_rule)
|
||||||
if(rule->actionset == NULL)
|
if(rule->actionset == NULL)
|
||||||
return "ModSecurity: Rules must have at least id action";
|
return "ModSecurity: Rules must have at least id action";
|
||||||
|
|
||||||
if(rule->actionset != NULL && (dcfg->tmp_chain_starter == NULL)) {
|
if(rule->actionset != NULL && (dcfg->tmp_chain_starter == NULL)) {
|
||||||
if(rule->actionset->id == NOT_SET_P
|
rule_actionset = (rule->actionset->id == NOT_SET_P);
|
||||||
#if defined(WITH_LUA)
|
#if defined(WITH_LUA)
|
||||||
&& (type != RULE_TYPE_LUA)
|
rule_actionset = (rule_actionset && (type != RULE_TYPE_LUA));
|
||||||
#endif
|
#endif
|
||||||
)
|
if (rule_actionset)
|
||||||
return "ModSecurity: No action id present within the rule";
|
return "ModSecurity: No action id present within the rule";
|
||||||
#if defined(WITH_LUA)
|
#if defined(WITH_LUA)
|
||||||
if(type != RULE_TYPE_LUA)
|
type_with_lua = (type != RULE_TYPE_LUA);
|
||||||
#endif
|
#endif
|
||||||
{
|
if (type_with_lua){
|
||||||
rid = apr_hash_get(dcfg->rule_id_htab, rule->actionset->id, APR_HASH_KEY_STRING);
|
rid = apr_hash_get(dcfg->rule_id_htab, rule->actionset->id, APR_HASH_KEY_STRING);
|
||||||
if(rid != NULL) {
|
if(rid != NULL) {
|
||||||
return "ModSecurity: Found another rule with the same id";
|
return "ModSecurity: Found another rule with the same id";
|
||||||
@@ -1666,7 +1669,7 @@ static const char *cmd_rule_perf_time(cmd_parms *cmd, void *_dcfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *parser_conn_limits_operator(apr_pool_t *mp, const char *p2,
|
char *parser_conn_limits_operator(apr_pool_t *mp, const char *p2,
|
||||||
TreeRoot **whitelist, TreeRoot **suspicious_list,
|
TreeRoot **whitelist, TreeRoot **suspicious_list,
|
||||||
const char *filename)
|
const char *filename)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
@@ -1753,7 +1756,7 @@ static const char *cmd_conn_read_state_limit(cmd_parms *cmd, void *_dcfg,
|
|||||||
if (param)
|
if (param)
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn_read_state_limit = limit;
|
conn_read_state_limit = limit;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@@ -1086,6 +1086,7 @@ static void hook_error_log(const char *file, int line, int level, apr_status_t s
|
|||||||
{
|
{
|
||||||
modsec_rec *msr = NULL;
|
modsec_rec *msr = NULL;
|
||||||
error_message_t *em = NULL;
|
error_message_t *em = NULL;
|
||||||
|
int msr_ap_server;
|
||||||
|
|
||||||
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
|
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
|
||||||
if (info == NULL) return;
|
if (info == NULL) return;
|
||||||
@@ -1102,15 +1103,15 @@ static void hook_error_log(const char *file, int line, int level, apr_status_t s
|
|||||||
|
|
||||||
/* Create a context for requests we never had the chance to process */
|
/* Create a context for requests we never had the chance to process */
|
||||||
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
|
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
|
||||||
if ((msr == NULL)
|
msr_ap_server = ((msr == NULL)
|
||||||
&& ((info->level & APLOG_LEVELMASK) < APLOG_DEBUG)
|
&& ((info->level & APLOG_LEVELMASK) < APLOG_DEBUG)
|
||||||
&& apr_table_get(info->r->subprocess_env, "UNIQUE_ID"))
|
&& apr_table_get(info->r->subprocess_env, "UNIQUE_ID"));
|
||||||
#else
|
#else
|
||||||
if ((msr == NULL)
|
msr_ap_server = ((msr == NULL)
|
||||||
&& ((level & APLOG_LEVELMASK) < APLOG_DEBUG)
|
&& ((level & APLOG_LEVELMASK) < APLOG_DEBUG)
|
||||||
&& apr_table_get(r->subprocess_env, "UNIQUE_ID"))
|
&& apr_table_get(r->subprocess_env, "UNIQUE_ID"));
|
||||||
#endif
|
#endif
|
||||||
{
|
if (msr_ap_server) {
|
||||||
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
|
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
|
||||||
msr = create_tx_context((request_rec *)info->r);
|
msr = create_tx_context((request_rec *)info->r);
|
||||||
#else
|
#else
|
||||||
@@ -1484,7 +1485,7 @@ static int hook_connection_early(conn_rec *conn)
|
|||||||
conn_read_state_suspicious_list, client_ip, NULL, &error_msg) <= 0))
|
conn_read_state_suspicious_list, client_ip, NULL, &error_msg) <= 0))
|
||||||
{
|
{
|
||||||
if (conn_limits_filter_state == MODSEC_DETECTION_ONLY)
|
if (conn_limits_filter_state == MODSEC_DETECTION_ONLY)
|
||||||
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
|
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
|
||||||
"ModSecurity: Too many threads [%ld] of %ld allowed " \
|
"ModSecurity: Too many threads [%ld] of %ld allowed " \
|
||||||
"in READ state from %s - There is a suspission list " \
|
"in READ state from %s - There is a suspission list " \
|
||||||
"but that IP is not part of it, access granted",
|
"but that IP is not part of it, access granted",
|
||||||
|
@@ -432,6 +432,7 @@ AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg,
|
|||||||
apr_file_t *file = NULL;
|
apr_file_t *file = NULL;
|
||||||
apr_finfo_t finfo;
|
apr_finfo_t finfo;
|
||||||
apr_status_t status;
|
apr_status_t status;
|
||||||
|
int exist_type;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
char buf[120];
|
char buf[120];
|
||||||
#endif
|
#endif
|
||||||
@@ -457,13 +458,13 @@ AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg,
|
|||||||
if (status != APR_SUCCESS)
|
if (status != APR_SUCCESS)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (finfo.filetype != APR_REG &&
|
exist_type = (finfo.filetype != APR_REG);
|
||||||
#if defined(WIN32) || defined(OS2) || defined(NETWARE)
|
#if defined(WIN32) || defined(OS2) || defined(NETWARE)
|
||||||
strcasecmp(apr_filepath_name_get(name), "nul") != 0) {
|
exist_type = (exist_type && strcasecmp(apr_filepath_name_get(name), "nul") != 0);
|
||||||
#else
|
#else
|
||||||
strcmp(name, "/dev/null") != 0) {
|
exist_type = (exist_type && strcmp(name, "/dev/null") != 0);
|
||||||
#endif /* WIN32 || OS2 */
|
#endif /* WIN32 || OS2 */
|
||||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
|
if (exist_type){ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
|
||||||
"Access to file %s denied by server: not a regular file",
|
"Access to file %s denied by server: not a regular file",
|
||||||
name);
|
name);
|
||||||
apr_file_close(file);
|
apr_file_close(file);
|
||||||
@@ -503,7 +504,7 @@ AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg,
|
|||||||
#else
|
#else
|
||||||
new_cfg->getch = cfg_getch;
|
new_cfg->getch = cfg_getch;
|
||||||
new_cfg->getstr = cfg_getstr;
|
new_cfg->getstr = cfg_getstr;
|
||||||
new_cfg->close = cfg_close;
|
new_cfg->close = cfg_close;
|
||||||
#endif
|
#endif
|
||||||
new_cfg->line_number = 0;
|
new_cfg->line_number = 0;
|
||||||
*ret_cfg = new_cfg;
|
*ret_cfg = new_cfg;
|
||||||
|
Reference in New Issue
Block a user