Skip to content

Commit aab128f

Browse files
committed
Code cosmetics: checks if actionset is not null before use it
1 parent a677456 commit aab128f

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

apache2/apache2_config.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ static void copy_rules_phase(apr_pool_t *mp,
239239

240240
/* Copy the rule. */
241241
*(msre_rule **)apr_array_push(child_phase_arr) = rule;
242-
if (rule->actionset->is_chained) mode = 2;
242+
if (rule->actionset && rule->actionset->is_chained) mode = 2;
243243
} else {
244-
if (rule->actionset->is_chained) mode = 1;
244+
if (rule->actionset && rule->actionset->is_chained) mode = 1;
245245
}
246246
} else {
247247
if (mode == 2) {
@@ -897,8 +897,10 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
897897
rule->actionset, 1);
898898

899899
/* Keep track of the parent action for "block" */
900-
rule->actionset->parent_intercept_action_rec = dcfg->tmp_default_actionset->intercept_action_rec;
901-
rule->actionset->parent_intercept_action = dcfg->tmp_default_actionset->intercept_action;
900+
if (rule->actionset) {
901+
rule->actionset->parent_intercept_action_rec = dcfg->tmp_default_actionset->intercept_action_rec;
902+
rule->actionset->parent_intercept_action = dcfg->tmp_default_actionset->intercept_action;
903+
}
902904

903905
/* Must NOT specify a disruptive action in logging phase. */
904906
if ((rule->actionset != NULL)
@@ -913,7 +915,9 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
913915

914916
if (dcfg->tmp_chain_starter != NULL) {
915917
rule->chain_starter = dcfg->tmp_chain_starter;
916-
rule->actionset->phase = rule->chain_starter->actionset->phase;
918+
if (rule->actionset) {
919+
rule->actionset->phase = rule->chain_starter->actionset->phase;
920+
}
917921
}
918922

919923
if (rule->actionset->is_chained != 1) {

apache2/re.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ static apr_status_t msre_ruleset_process_phase_(msre_ruleset *ruleset, modsec_re
17811781
}
17821782

17831783
if (rc == RULE_NO_MATCH) {
1784-
if (rule->actionset->is_chained) {
1784+
if (rule->actionset && rule->actionset->is_chained) {
17851785
/* If the current rule is part of a chain then
17861786
* we need to skip over all the rules in the chain.
17871787
*/
@@ -2138,9 +2138,9 @@ static int msre_ruleset_phase_rule_remove_with_exception(msre_ruleset *ruleset,
21382138
if (remove_rule) {
21392139
/* Do not increment j. */
21402140
removed_count++;
2141-
if (rule->actionset->is_chained) mode = 2; /* Remove rules in this chain. */
2141+
if (rule->actionset && rule->actionset->is_chained) mode = 2; /* Remove rules in this chain. */
21422142
} else {
2143-
if (rule->actionset->is_chained) mode = 1; /* Keep rules in this chain. */
2143+
if (rule->actionset && rule->actionset->is_chained) mode = 1; /* Keep rules in this chain. */
21442144
rules[j++] = rules[i];
21452145
}
21462146
} else { /* Handling rule that is part of a chain. */

apache2/re_operators.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,9 @@ static int msre_op_verifyCC_execute(modsec_rec *msr, msre_rule *rule, msre_var *
28512851
* and we are done.
28522852
*/
28532853

2854-
matched_bytes = apr_table_get(rule->actionset->actions, "sanitizeMatchedBytes") ? 1 : 0;
2854+
if (rule->actionset) {
2855+
matched_bytes = apr_table_get(rule->actionset->actions, "sanitizeMatchedBytes") ? 1 : 0;
2856+
}
28552857
if(!matched_bytes)
28562858
matched_bytes = apr_table_get(rule->actionset->actions, "sanitiseMatchedBytes") ? 1 : 0;
28572859

@@ -3159,7 +3161,9 @@ static int msre_op_verifyCPF_execute(modsec_rec *msr, msre_rule *rule, msre_var
31593161
* and we are done.
31603162
*/
31613163

3162-
matched_bytes = apr_table_get(rule->actionset->actions, "sanitizeMatchedBytes") ? 1 : 0;
3164+
if (rule->actionset) {
3165+
matched_bytes = apr_table_get(rule->actionset->actions, "sanitizeMatchedBytes") ? 1 : 0;
3166+
}
31633167
if(!matched_bytes)
31643168
matched_bytes = apr_table_get(rule->actionset->actions, "sanitiseMatchedBytes") ? 1 : 0;
31653169

@@ -3451,7 +3455,9 @@ static int msre_op_verifySSN_execute(modsec_rec *msr, msre_rule *rule, msre_var
34513455
* and we are done.
34523456
*/
34533457

3454-
matched_bytes = apr_table_get(rule->actionset->actions, "sanitizeMatchedBytes") ? 1 : 0;
3458+
if (rule->actionset) {
3459+
matched_bytes = apr_table_get(rule->actionset->actions, "sanitizeMatchedBytes") ? 1 : 0;
3460+
}
34553461
if(!matched_bytes)
34563462
matched_bytes = apr_table_get(rule->actionset->actions, "sanitiseMatchedBytes") ? 1 : 0;
34573463

0 commit comments

Comments
 (0)