Skip to content

Commit 3a7fdf8

Browse files
wmarquesrFelipe Zimmerle
authored andcommitted
Refactoring conditional directives for if wrappers, alternative if statements and incomplete if conditions.
1 parent c373256 commit 3a7fdf8

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

apache2/apache2_config.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,9 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
755755
char *rid = NULL;
756756
msre_rule *rule = NULL;
757757
extern msc_engine *modsecurity;
758+
int type_with_lua = 1;
759+
int type_rule;
760+
int rule_actionset;
758761
int offset = 0;
759762

760763
#ifdef DEBUG_CONF
@@ -787,25 +790,25 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
787790
}
788791

789792
/* Rules must have uniq ID */
790-
if (
793+
type_rule = (dcfg->tmp_chain_starter == NULL);
791794
#if defined(WITH_LUA)
792-
type != RULE_TYPE_LUA &&
795+
type_rule = (type != RULE_TYPE_LUA && type_rule);
793796
#endif
794-
(dcfg->tmp_chain_starter == NULL))
797+
if (type_rule)
795798
if(rule->actionset == NULL)
796799
return "ModSecurity: Rules must have at least id action";
797800

798801
if(rule->actionset != NULL && (dcfg->tmp_chain_starter == NULL)) {
799-
if(rule->actionset->id == NOT_SET_P
802+
rule_actionset = (rule->actionset->id == NOT_SET_P);
800803
#if defined(WITH_LUA)
801-
&& (type != RULE_TYPE_LUA)
804+
rule_actionset = (rule_actionset && (type != RULE_TYPE_LUA));
802805
#endif
803-
)
804-
return "ModSecurity: No action id present within the rule";
806+
if (rule_actionset)
807+
return "ModSecurity: No action id present within the rule";
805808
#if defined(WITH_LUA)
806-
if(type != RULE_TYPE_LUA)
809+
type_with_lua = (type != RULE_TYPE_LUA);
807810
#endif
808-
{
811+
if (type_with_lua){
809812
rid = apr_hash_get(dcfg->rule_id_htab, rule->actionset->id, APR_HASH_KEY_STRING);
810813
if(rid != NULL) {
811814
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,
16661669
}
16671670

16681671
char *parser_conn_limits_operator(apr_pool_t *mp, const char *p2,
1669-
TreeRoot **whitelist, TreeRoot **suspicious_list,
1672+
TreeRoot **whitelist, TreeRoot **suspicious_list,
16701673
const char *filename)
16711674
{
16721675
int res = 0;
@@ -1753,7 +1756,7 @@ static const char *cmd_conn_read_state_limit(cmd_parms *cmd, void *_dcfg,
17531756
if (param)
17541757
return param;
17551758
}
1756-
1759+
17571760
conn_read_state_limit = limit;
17581761

17591762
return NULL;

apache2/mod_security2.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ static void hook_error_log(const char *file, int line, int level, apr_status_t s
10861086
{
10871087
modsec_rec *msr = NULL;
10881088
error_message_t *em = NULL;
1089+
int msr_ap_server;
10891090

10901091
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
10911092
if (info == NULL) return;
@@ -1102,15 +1103,15 @@ static void hook_error_log(const char *file, int line, int level, apr_status_t s
11021103

11031104
/* Create a context for requests we never had the chance to process */
11041105
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
1105-
if ((msr == NULL)
1106+
msr_ap_server = ((msr == NULL)
11061107
&& ((info->level & APLOG_LEVELMASK) < APLOG_DEBUG)
1107-
&& apr_table_get(info->r->subprocess_env, "UNIQUE_ID"))
1108+
&& apr_table_get(info->r->subprocess_env, "UNIQUE_ID"));
11081109
#else
1109-
if ((msr == NULL)
1110+
msr_ap_server = ((msr == NULL)
11101111
&& ((level & APLOG_LEVELMASK) < APLOG_DEBUG)
1111-
&& apr_table_get(r->subprocess_env, "UNIQUE_ID"))
1112+
&& apr_table_get(r->subprocess_env, "UNIQUE_ID"));
11121113
#endif
1113-
{
1114+
if (msr_ap_server) {
11141115
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
11151116
msr = create_tx_context((request_rec *)info->r);
11161117
#else
@@ -1484,7 +1485,7 @@ static int hook_connection_early(conn_rec *conn)
14841485
conn_read_state_suspicious_list, client_ip, NULL, &error_msg) <= 0))
14851486
{
14861487
if (conn_limits_filter_state == MODSEC_DETECTION_ONLY)
1487-
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
1488+
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
14881489
"ModSecurity: Too many threads [%ld] of %ld allowed " \
14891490
"in READ state from %s - There is a suspission list " \
14901491
"but that IP is not part of it, access granted",

standalone/config.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg,
432432
apr_file_t *file = NULL;
433433
apr_finfo_t finfo;
434434
apr_status_t status;
435+
int exist_type;
435436
#ifdef DEBUG
436437
char buf[120];
437438
#endif
@@ -457,13 +458,13 @@ AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg,
457458
if (status != APR_SUCCESS)
458459
return status;
459460

460-
if (finfo.filetype != APR_REG &&
461+
exist_type = (finfo.filetype != APR_REG);
461462
#if defined(WIN32) || defined(OS2) || defined(NETWARE)
462-
strcasecmp(apr_filepath_name_get(name), "nul") != 0) {
463+
exist_type = (exist_type && strcasecmp(apr_filepath_name_get(name), "nul") != 0);
463464
#else
464-
strcmp(name, "/dev/null") != 0) {
465+
exist_type = (exist_type && strcmp(name, "/dev/null") != 0);
465466
#endif /* WIN32 || OS2 */
466-
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
467+
if (exist_type){ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
467468
"Access to file %s denied by server: not a regular file",
468469
name);
469470
apr_file_close(file);
@@ -503,7 +504,7 @@ AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg,
503504
#else
504505
new_cfg->getch = cfg_getch;
505506
new_cfg->getstr = cfg_getstr;
506-
new_cfg->close = cfg_close;
507+
new_cfg->close = cfg_close;
507508
#endif
508509
new_cfg->line_number = 0;
509510
*ret_cfg = new_cfg;

0 commit comments

Comments
 (0)