@@ -48,6 +48,13 @@ static apr_status_t msre_rule_process(msre_rule *rule, modsec_rec *msr);
4848
4949/* -- Actions, variables, functions and operator functions ----------------- */
5050
51+ // Returns the rule id if existing, otherwise the file name & line number
52+ static const char * id_log (msre_rule * rule ) {
53+ const char * id = rule -> actionset -> id ;
54+ if (!id || !* id || id == NOT_SET_P ) id = apr_psprintf (rule -> ruleset -> mp , "%s (%d)" , rule -> filename , rule -> line_num );
55+ return id ;
56+ }
57+
5158/**
5259 * \brief Remove rule targets to be processed
5360 *
@@ -94,7 +101,7 @@ static int fetch_target_exception(msre_rule *rule, modsec_rec *msr, msre_var *va
94101
95102 if (targets != NULL ) {
96103 if (msr -> txcfg -> debuglog_level >= 9 ) {
97- msr_log (msr , 9 , "fetch_target_exception: Found exception target list [%s] for rule id %s" , targets , rule -> actionset -> id );
104+ msr_log (msr , 9 , "fetch_target_exception: Found exception target list [%s] for rule id %s" , targets , id_log ( rule ) );
98105 }
99106 target = apr_strtok ((char * )targets , "," , & savedptr );
100107
@@ -139,7 +146,7 @@ static int fetch_target_exception(msre_rule *rule, modsec_rec *msr, msre_var *va
139146 }
140147 } else {
141148 if (msr -> txcfg -> debuglog_level >= 9 ) {
142- msr_log (msr , 9 , "fetch_target_exception: No exception target found for rule id %s." , rule -> actionset -> id );
149+ msr_log (msr , 9 , "fetch_target_exception: No exception target found for rule id %s." , id_log ( rule ) );
143150
144151 }
145152 }
@@ -1583,7 +1590,7 @@ static apr_status_t msre_ruleset_process_phase_(msre_ruleset *ruleset, modsec_re
15831590 saw_starter = 0 ;
15841591
15851592 if (msr -> txcfg -> debuglog_level >= 9 ) {
1586- msr_log (msr , 9 , "Current rule is id=\"%s\" [chained %d] is trying to find the SecMarker=\"%s\" [stater %d]" ,rule -> actionset -> id ,last_rule -> actionset -> is_chained ,skip_after ,saw_starter );
1593+ msr_log (msr , 9 , "Current rule is id=\"%s\" [chained %d] is trying to find the SecMarker=\"%s\" [stater %d]" , id_log ( rule ) ,last_rule -> actionset -> is_chained ,skip_after ,saw_starter );
15871594 }
15881595
15891596 }
@@ -1740,7 +1747,7 @@ static apr_status_t msre_ruleset_process_phase_(msre_ruleset *ruleset, modsec_re
17401747 msr_log (msr , 5 , "Not processing %srule id=\"%s\": "
17411748 "removed by ctl action" ,
17421749 rule -> actionset -> is_chained ? "chained " : "" ,
1743- rule -> actionset -> id );
1750+ id_log ( rule ) );
17441751 }
17451752
17461753 /* Skip the whole chain, if this is a chained rule */
@@ -1910,15 +1917,11 @@ static apr_status_t msre_ruleset_process_phase_(msre_ruleset *ruleset, modsec_re
19101917 }
19111918 }
19121919 else if (rc < 0 ) {
1913- const char * id = "" ;
19141920 const char * msg = "" ;
1915- if (rule -> actionset -> id ) {
1916- id = rule -> actionset -> id ;
1917- }
19181921 if (rule -> actionset -> msg ) {
19191922 msg = rule -> actionset -> msg ;
19201923 }
1921- msr_log (msr , 1 , "Rule processing failed (id=%s, msg=%s)." , id , msg );
1924+ msr_log (msr , 1 , "Rule processing failed (id=%s, msg=%s)." , id_log ( rule ) , msg );
19221925
19231926 if (msr -> txcfg -> reqintercept_oe == 1 ) {
19241927 apr_table_clear (msr -> matched_vars );
@@ -1948,15 +1951,11 @@ static apr_status_t msre_ruleset_process_phase_(msre_ruleset *ruleset, modsec_re
19481951 }
19491952 }
19501953 else {
1951- const char * id = "" ;
19521954 const char * msg = "" ;
1953- if (rule -> actionset -> id ) {
1954- id = rule -> actionset -> id ;
1955- }
19561955 if (rule -> actionset -> msg ) {
19571956 msg = rule -> actionset -> msg ;
19581957 }
1959- msr_log (msr , 1 , "Rule processing failed with unknown return code: %d (id=%s, msg=%s)." , rc , id , msg );
1958+ msr_log (msr , 1 , "Rule processing failed with unknown return code: %d (id=%s, msg=%s)." , rc , id_log ( rule ) , msg );
19601959 apr_table_clear (msr -> matched_vars );
19611960 return -1 ;
19621961 }
0 commit comments