Skip to content

CI improvement: First check syntax & always display error.log #3172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 138 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
2c8430c
Check for invalid pointers
Jul 31, 2023
448f307
https://github.com/SpiderLabs/ModSecurity/issues/533
Aug 8, 2023
2bc929f
another NULL pointer check
Aug 8, 2023
4e21013
another NULL pointer check
Aug 8, 2023
0614de0
Approach version
Aug 8, 2023
057f34b
Add environment variable with mod_security2 version number
Aug 8, 2023
1965e29
Remove redundant tags (and actions)
Aug 11, 2023
fc3dc17
https://github.com/SpiderLabs/ModSecurity/issues/2927
Aug 11, 2023
7709b49
Logging enhancement: show if rule is chained, in case of no id, show …
Aug 11, 2023
ef45e17
Allow multiple digits in sanitizeMatchedBytes
Aug 11, 2023
907ae5c
Handle capture as tx.1=char in validateByteRange
Aug 11, 2023
00bf4f2
Fix ErrorDocument processing if status is changed during phase 4
Aug 11, 2023
154c587
Update apache2_io.c
Aug 14, 2023
70110bc
Support for "filename*" in multipart (precedence over "filename").
Aug 16, 2023
f429b41
status 400 instead of 500 on parsing error
Aug 16, 2023
62ca3d8
cleanup
Aug 16, 2023
322486a
Allow macro expansion in ctl:ruleRemoveTargetByTag
Aug 16, 2023
12791df
Merge pull request #30 from marcstern/v2/approach/version
Aug 18, 2023
0c5bcbe
Merge pull request #31 from marcstern/v2/mst/expand_ruleRemoveTargetBy
Aug 18, 2023
f9143b7
Merge pull request #32 from marcstern/v2/mst/nullcheck
Aug 18, 2023
95803c4
Merge pull request #33 from marcstern/v2/mst/username
Aug 18, 2023
e5edb42
Merge pull request #34 from marcstern/v2/mst/yajl_compat
Aug 18, 2023
38fecd7
Merge pull request #35 from marcstern/v2/mst/issue533
Aug 18, 2023
6943ca2
Merge branch 'v2/latest' into v2/mst/issue2849
Aug 18, 2023
fc4596a
Merge pull request #36 from marcstern/v2/mst/issue2849
Aug 18, 2023
7583a9e
Merge pull request #37 from marcstern/v2/mst/json400
Aug 18, 2023
7b35355
Merge pull request #38 from marcstern/v2/mst/issue610
Aug 18, 2023
f34ae55
Merge pull request #39 from marcstern/v2/mst/filenamestar
Aug 18, 2023
1f3832b
Merge pull request #40 from marcstern/v2/mst/debug_conf
Aug 18, 2023
006ed1b
Merge pull request #41 from marcstern/v2/mst/mem_leak1
Aug 18, 2023
c2837cc
Merge pull request #42 from marcstern/v2/mst/rc_check
Aug 18, 2023
b4bd553
Merge pull request #43 from marcstern/v2/mst/capturebyte
Aug 18, 2023
5a62492
Merge pull request #44 from marcstern/v2/mst/optim2
Aug 18, 2023
2be1e05
Merge pull request #45 from marcstern/v2/mst/optim1
Aug 18, 2023
f24334a
Merge pull request #46 from marcstern/v2/mst/sanit_bytes
Aug 18, 2023
a046af5
Merge pull request #47 from marcstern/v2/mst/log_noid
Aug 18, 2023
29c8c48
Merge pull request #48 from marcstern/v2/mst/issue2927
Aug 18, 2023
30ffc2e
Merge pull request #49 from marcstern/v2/mst/redundant_actions
Aug 18, 2023
1c45f27
Merge pull request #50 from marcstern/v2/mst/version
Aug 18, 2023
728dceb
Merge pull request #51 from marcstern/v2/approach/version
Aug 18, 2023
98caa02
set pointer to NULL after free
Aug 18, 2023
024fc05
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 18, 2023
e842270
Update mod_security2.c
Aug 18, 2023
e8c6ac6
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 18, 2023
b47f117
NULL pointer check
Aug 18, 2023
a20cb78
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 18, 2023
6739643
Merge pull request #52 from marcstern/v2/mst/yajl_compat
Aug 18, 2023
0682a2f
Merge branch '!latest' of https://github.com/marcstern/ModSecurity in…
Aug 18, 2023
8c3b6b9
Merge branch 'v2/mst/yajl_compat' of https://github.com/marcstern/Mod…
Aug 18, 2023
304b7b0
Merge branch 'v2/mst/yajl_compat' of https://github.com/marcstern/Mod…
Aug 18, 2023
93d562e
Merge branch 'v2/mst/username' of https://github.com/marcstern/ModSec…
Aug 18, 2023
44ace42
Update msc_logging.c
Aug 18, 2023
a8566ee
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 18, 2023
fdb0353
Update msc_reqbody.c
Aug 18, 2023
141631c
Merge branch 'v2/mst/json400' of https://github.com/marcstern/ModSecu…
Aug 18, 2023
255817d
Merge branch 'v2/mst/username' of https://github.com/marcstern/ModSec…
Aug 18, 2023
950f7ff
NULL pointer check
Aug 18, 2023
05f9634
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 18, 2023
0373c8d
Update re_actions.c
Aug 18, 2023
e121167
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 18, 2023
ec94d43
Merge branch 'v2/mst/optim2' of https://github.com/marcstern/ModSecur…
Aug 21, 2023
2fd4470
Merge branch 'v2/mst/optim2' of https://github.com/marcstern/ModSecur…
Aug 21, 2023
eff64db
; incorrectly replaced by space in cmdline
Aug 21, 2023
ea721f9
Merge pull request #53 from marcstern/v2/mst/cmdline-semicolon
Aug 21, 2023
9561122
Merge branch '!latest' of https://github.com/marcstern/ModSecurity in…
Aug 21, 2023
2772a88
Merge branch 'v2/mst/mem_leak1' of https://github.com/marcstern/ModSe…
Aug 21, 2023
351a9a2
Double memory allocation:
Aug 21, 2023
a878d91
Merge pull request #54 from marcstern/v2/mst/optim3
Aug 21, 2023
1b272c9
Merge branch '!latest' of https://github.com/marcstern/ModSecurity in…
Aug 21, 2023
cfe5393
Update re_operators.c
Aug 21, 2023
59cff80
other NULL checks
Aug 21, 2023
fe9c8f3
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 21, 2023
9e96a5e
Fixed NULL check
Aug 21, 2023
4f2cda0
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 21, 2023
d257939
Merge pull request #56 from marcstern/v2/mst/expand_ruleRemoveTargetBy
Aug 21, 2023
d3f59fc
Fixed merge problem
Aug 21, 2023
f6d18d6
Another NULL check fix
Aug 21, 2023
342954b
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 21, 2023
6902288
Another NULL check fix
Aug 21, 2023
bc61a5d
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 21, 2023
1b87df5
Another NULL check
Aug 21, 2023
96fca5a
Update re.c
Aug 21, 2023
8ff9dc8
Merge branch 'v2/mst/log_noid' of https://github.com/marcstern/ModSec…
Aug 21, 2023
eb0200c
Update re.c
Aug 21, 2023
6fba059
Merge branch 'v2/mst/log_noid' of https://github.com/marcstern/ModSec…
Aug 21, 2023
3d10c4d
Another NULL check
Aug 21, 2023
870af0c
Another NULL check
Aug 21, 2023
861bb6f
Fixed another NULL check
Aug 21, 2023
34200f4
Other NULL checks
Aug 21, 2023
8612663
Update apache2_config.c
Aug 22, 2023
4bcd1c6
Update apache2_config.c
Aug 22, 2023
e7ef85d
Merge branch 'v2/mst/log_noid' of https://github.com/marcstern/ModSec…
Aug 22, 2023
18c5243
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 22, 2023
06d94c7
PCRE2 support
Aug 22, 2023
8e4b1d9
Merge branch '!latest' of https://github.com/marcstern/ModSecurity in…
Aug 22, 2023
36a1c7b
Other null checks
Aug 22, 2023
30c19ec
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 22, 2023
2422dc8
Merge branch 'v2/mst/redundant_actions' of https://github.com/marcste…
Aug 22, 2023
3e7306a
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 22, 2023
9dabfe3
another NULL check
Aug 22, 2023
e4bf4be
Merge branch 'v2/mst/nullcheck' of https://github.com/marcstern/ModSe…
Aug 22, 2023
4e48b41
Update msc_release.h
Aug 22, 2023
80007c2
Merge branch 'v2/approach/version' of https://github.com/marcstern/Mo…
Aug 22, 2023
211b341
Merge branch 'v2/master' of https://github.com/marcstern/ModSecurity …
Aug 24, 2023
7e073ab
generalized & centralized fix
Sep 26, 2023
b84152c
Reverted changes logging empty id, as context is already present
Sep 26, 2023
3e5f182
used NOT_SET_P instead of value
Sep 26, 2023
c432f3c
rule->actionset is never NULL
Sep 26, 2023
fee6bd9
Store "sanitizeMatched" & "sanitizeMatchedBytes" as "sanitiseMatched"…
Oct 4, 2023
0614cd6
for all "sanitize" actions
Oct 4, 2023
8376240
Update re.c
Oct 4, 2023
268fa50
Merge branch '!latest' into v2/mst/log_noid
Oct 4, 2023
ef08786
Merge pull request #60 from marcstern/v2/mst/log_noid
Oct 4, 2023
4ae61a6
Merge pull request #61 from marcstern/v2/mst/redundant_actions
Oct 4, 2023
abd48e4
Merge pull request #59 from marcstern/v2/mst/expand_macros_optim
Oct 4, 2023
d0b1a49
Merge branch '!latest' into v2/mst/sanitise_alias
Oct 4, 2023
6342e74
Merge pull request #62 from marcstern/v2/mst/sanitise_alias
Oct 4, 2023
188dc6b
Merge pull request #63 from marcstern/v2/mst/jit_not_init
Oct 4, 2023
b46187f
missing }
Oct 4, 2023
bd8955a
Merge pull request #64 from marcstern/v2/mst/sanitise_alias
Oct 4, 2023
4b2c726
Merge pull request #65 from marcstern/v2/mst/phase_validate
Oct 5, 2023
5c475db
Allow to store only the length of ARGS values in ARGS_COMBINED_SIZE. …
Oct 20, 2023
25043be
Merge pull request #66 from marcstern/v2/mst/target_log
Oct 20, 2023
a3b1fb3
Merge pull request #67 from marcstern/v2/mst/ARGS_COMBINED_SIZE
Oct 20, 2023
40ce625
Revert "Support for "filename*" in multipart (precedence over "filena…
Oct 24, 2023
98a682e
Merge pull request #69 from marcstern/v2/mst/empty_action
Oct 26, 2023
a33034f
Merge pull request #70 from marcstern/v2/mst/optim4
Oct 26, 2023
7369af4
Merge pull request #71 from marcstern/v2/tag_loop_break
Oct 31, 2023
165bce7
Merge pull request #72 from marcstern/v2/mst/except_noid
Nov 2, 2023
9fcae1a
Log involved collection key in case of DBM write error
Nov 22, 2023
a726c96
Merge branch '!latest' into v2/mst/log_coll_key
Nov 24, 2023
f3565d1
Merge pull request #73 from marcstern/v2/mst/log_coll_key
Nov 24, 2023
e61a91a
First check syntax, in case no error.log is generated.
Jun 13, 2024
9c769e1
Show mod_security2 audit log
Jun 14, 2024
638ecce
test
Jun 14, 2024
cb43194
/var/log/apache2/modsec_audit.log
Jun 14, 2024
dbb80bd
Add audit log
Jun 25, 2024
21990de
Merge branch '!latest' into v2/ci_errorlog2
Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/security2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so
SecDataDir /var/cache/modsecurity
Include /etc/apache2/modsecurity.conf
</IfModule>

SecAuditLog /var/log/apache2/modsec_audit.log
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ jobs:
sudo cp unicode.mapping /etc/apache2/
sudo mkdir -p /var/cache/modsecurity
sudo chown -R www-data:www-data /var/cache/modsecurity
- name: first check config (to get syntax errors)
run: sudo apachectl configtest
- name: start apache with module
run: |
sudo systemctl restart apache2.service
sudo cat /var/log/apache2/error.log

run: sudo systemctl restart apache2.service
- name: Show httpd error log
if: always()
run: sudo cat /var/log/apache2/error.log
- name: Show mod_security2 audit log
if: always()
run: sudo cat /var/log/apache2/modsec_audit.log
# For non-regression tests: /home/runner/work/ModSecurity/ModSecurity/tests/regression/server_root/logs/audit/audit.log
33 changes: 16 additions & 17 deletions apache2/apache2_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
APLOG_USE_MODULE(security2);
#endif

// Returns the rule id if existing, otherwise the file name & line number
const char* id_log(msre_rule* rule) {
assert(rule != NULL);
assert(rule->actionset != NULL);
static const char* id_log(msre_rule* rule) {
const char* id = rule->actionset->id;
if (!id || !*id || id == NOT_SET_P) id = apr_psprintf(rule->ruleset->mp, "%s (%d)", rule->filename, rule->line_num);
return id;
if (id == NOT_SET_P || !*id) id = apr_psprintf(rule->ruleset->mp, "%s (%d)", rule->filename, rule->line_num);
return id;
}

/* -- Directory context creation and initialisation -- */
Expand Down Expand Up @@ -903,7 +900,7 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
}

/* Must NOT use skip. */
if (rule->actionset->skip_count != NOT_SET) {
if (rule->actionset && rule->actionset->skip_count != NOT_SET) {
return apr_psprintf(cmd->pool, "ModSecurity: The skip action can only be used "
" by chain starter rules. ");
}
Expand Down Expand Up @@ -936,7 +933,7 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
rule->actionset->phase = rule->chain_starter->actionset->phase;
}

if (rule->actionset->is_chained != 1) {
if (rule->actionset && rule->actionset->is_chained != 1) {
/* If this rule is part of the chain but does
* not want more rules to follow in the chain
* then cut it (the chain).
Expand All @@ -959,7 +956,7 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
}

/* Keep track of any rule IDs we need to skip after */
if (rule->actionset->skip_after != NOT_SET_P) {
if (rule->actionset && rule->actionset->skip_after != NOT_SET_P) {
char *tmp_id = apr_pstrdup(cmd->pool, rule->actionset->skip_after);
apr_table_setn(dcfg->tmp_rule_placeholders, tmp_id, tmp_id);

Expand All @@ -976,33 +973,33 @@ static const char *add_rule(cmd_parms *cmd, directory_config *dcfg, int type,
#endif

/* Add rule to the recipe. */
if (msre_ruleset_rule_add(dcfg->ruleset, rule, rule->actionset->phase) < 0) {
if (rule->actionset && msre_ruleset_rule_add(dcfg->ruleset, rule, rule->actionset->phase) < 0) {
return "Internal Error: Failed to add rule to the ruleset.";
}

/* Add an additional placeholder if this rule ID is on the list */
if ((rule->actionset->id != NULL) && apr_table_get(dcfg->tmp_rule_placeholders, rule->actionset->id)) {
if (rule->actionset && (rule->actionset->id != NULL) && apr_table_get(dcfg->tmp_rule_placeholders, rule->actionset->id)) {
msre_rule *phrule = apr_palloc(rule->ruleset->mp, sizeof(msre_rule));
if (phrule == NULL) {
return FATAL_ERROR;
}

#ifdef DEBUG_CONF
ap_log_perror(APLOG_MARK, APLOG_STARTUP|APLOG_NOERRNO, 0, cmd->pool,
"Adding placeholder %pp for rule %pp id=\"%s\".", phrule, rule, rule->actionset->id);
"Adding placeholder %pp for rule %pp id=\"%s\".", phrule, rule, id_log(rule));
#endif

/* shallow copy of original rule with placeholder marked as target */
memcpy(phrule, rule, sizeof(msre_rule));
phrule->placeholder = RULE_PH_SKIPAFTER;

/* Add placeholder. */
if (msre_ruleset_rule_add(dcfg->ruleset, phrule, phrule->actionset->phase) < 0) {
if (phrule->actionset && msre_ruleset_rule_add(dcfg->ruleset, phrule, phrule->actionset->phase) < 0) {
return "Internal Error: Failed to add placeholder to the ruleset.";
}

/* No longer need to search for the ID */
apr_table_unset(dcfg->tmp_rule_placeholders, rule->actionset->id);
if (rule->actionset) apr_table_unset(dcfg->tmp_rule_placeholders, rule->actionset->id);
}

/* Update the unparsed rule */
Expand Down Expand Up @@ -1055,7 +1052,7 @@ static const char *add_marker(cmd_parms *cmd, directory_config *dcfg,
}

/* No longer need to search for the ID */
if (dcfg->tmp_rule_placeholders != NULL) {
if (rule->actionset && rule->actionset->id && dcfg->tmp_rule_placeholders != NULL) {
apr_table_unset(dcfg->tmp_rule_placeholders, rule->actionset->id);
}

Expand Down Expand Up @@ -1102,16 +1099,17 @@ static const char *update_rule_action(cmd_parms *cmd, directory_config *dcfg,
if (my_error_msg != NULL) return my_error_msg;

/* Must NOT change an id */
if ((new_actionset->id != NOT_SET_P) && (rule->actionset->id != NULL) && (strcmp(rule->actionset->id, new_actionset->id) != 0)) {
if ((new_actionset->id != NOT_SET_P) && rule->actionset && (rule->actionset->id != NULL) && (strcmp(rule->actionset->id, new_actionset->id) != 0)) {
return apr_psprintf(cmd->pool, "ModSecurity: Rule IDs cannot be updated via SecRuleUpdateActionById.");
}

/* Must NOT alter the phase */
if ((new_actionset->phase != NOT_SET) && (rule->actionset->phase != new_actionset->phase)) {
if ((new_actionset->phase != NOT_SET) && rule->actionset && (rule->actionset->phase != new_actionset->phase)) {
return apr_psprintf(cmd->pool, "ModSecurity: Rule phases cannot be updated via SecRuleUpdateActionById.");
}

#ifdef DEBUG_CONF
if (rule->actionset)
{
char *actions = msre_actionset_generate_action_string(ruleset->mp, rule->actionset);
ap_log_perror(APLOG_MARK, APLOG_STARTUP|APLOG_NOERRNO, 0, cmd->pool,
Expand All @@ -1131,6 +1129,7 @@ static const char *update_rule_action(cmd_parms *cmd, directory_config *dcfg,
rule->unparsed = msre_rule_generate_unparsed(ruleset->mp, rule, NULL, NULL, NULL);

#ifdef DEBUG_CONF
if (rule->actionset)
{
char *actions = msre_actionset_generate_action_string(ruleset->mp, rule->actionset);
ap_log_perror(APLOG_MARK, APLOG_STARTUP|APLOG_NOERRNO, 0, cmd->pool,
Expand Down
2 changes: 1 addition & 1 deletion apache2/apache2_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ apr_status_t output_filter(ap_filter_t *f, apr_bucket_brigade *bb_in) {

bucket_ci = apr_bucket_heap_create(msr->content_append,
msr->content_append_len, NULL, f->r->connection->bucket_alloc);
APR_BUCKET_INSERT_BEFORE(eos_bucket, bucket_ci);
if (eos_bucket) APR_BUCKET_INSERT_BEFORE(eos_bucket, bucket_ci);

if (msr->txcfg->debuglog_level >= 9) {
msr_log(msr, 9, "Content-Injection (b): Added content to bottom: %s",
Expand Down
1 change: 1 addition & 0 deletions apache2/apache2_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ apr_status_t send_error_bucket(modsec_rec *msr, ap_filter_t *f, int status) {

/* Set the status line explicitly for the error document */
f->r->status_line = ap_get_status_line(status);
f->r->status = 200; //MST: needed for custom error messages

brigade = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc);
if (brigade == NULL) return APR_EGENERAL;
Expand Down
7 changes: 6 additions & 1 deletion apache2/mod_security2.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ static const char *modsec_var_log_handler(request_rec *r, char *name) {

msr = retrieve_tx_context(r);
if (msr == NULL) return NULL;
if (msr->msc_rule_mptmp == NULL) return NULL;

return construct_single_var(msr, name);
}
Expand Down Expand Up @@ -776,7 +777,7 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
/* Log our presence to the error log. */
if (first_time) {
ap_log_error(APLOG_MARK, APLOG_NOTICE | APLOG_NOERRNO, 0, s,
"%s configured.", MODSEC_MODULE_NAME_FULL);
"%s configured.", MODSEC_MODULE_NAME_FULL2);

version(mp);

Expand All @@ -791,11 +792,13 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
if (status_engine_state != STATUS_ENGINE_DISABLED) {
msc_status_engine_call();
}
/*MST
else {
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
"ModSecurity: Status engine is currently disabled, enable " \
"it by set SecStatusEngine to On.");
}
*/
#endif
}

Expand Down Expand Up @@ -856,6 +859,8 @@ static int hook_request_early(request_rec *r) {
modsec_rec *msr = NULL;
int rc = DECLINED;

apr_table_set(r->subprocess_env, "ModSecVersion", MODSEC_MODULE_VERSION);

/* This function needs to run only once per transaction
* (i.e. subrequests and redirects are excluded).
*/
Expand Down
15 changes: 7 additions & 8 deletions apache2/msc_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,19 @@ int json_process_chunk(modsec_rec *msr, const char *buf, unsigned int size, char
assert(msr != NULL);
assert(error_msg != NULL);
*error_msg = NULL;
base_offset=buf;
// Take a copy in case libyajl decodes the buffer inline
base_offset = apr_pstrmemdup(msr->mp, buf, size);
if (!base_offset) return -1;

/* Feed our parser and catch any errors */
msr->json->status = yajl_parse(msr->json->handle, buf, size);
msr->json->status = yajl_parse(msr->json->handle, (unsigned char*)base_offset, size);
if (msr->json->status != yajl_status_ok) {
if (msr->json->depth_limit_exceeded) {
*error_msg = "JSON depth limit exceeded";
} else {
if (msr->json->yajl_error) *error_msg = msr->json->yajl_error;
else {
char* yajl_err = yajl_get_error(msr->json->handle, 0, buf, size);
*error_msg = apr_pstrdup(msr->mp, yajl_err);
yajl_free_error(msr->json->handle, yajl_err);
}
char *yajl_err = yajl_get_error(msr->json->handle, 0, base_offset, size);
*error_msg = apr_pstrdup(msr->mp, yajl_err);
yajl_free_error(msr->json->handle, yajl_err);
}
return -1;
}
Expand Down
22 changes: 8 additions & 14 deletions apache2/msc_logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,7 @@ static char *construct_auditlog_filename(apr_pool_t *mp, const char *uniqueid) {
* This is required for mpm-itk & mod_ruid2, though should be harmless for other implementations
* It also changes the return statement.
*/
char *userinfo;
apr_status_t rc;
apr_uid_t uid;
apr_gid_t gid;
apr_uid_current(&uid, &gid, mp);
rc = apr_uid_name_get(&userinfo, uid, mp);
if (rc != APR_SUCCESS) {
userinfo = apr_psprintf(mp, "%u", uid);
}
char *userinfo = get_username(mp);

apr_time_exp_lt(&t, apr_time_now());

Expand Down Expand Up @@ -1470,15 +1462,17 @@ void sec_audit_logger_json(modsec_rec *msr) {
* as it does not need an index file.
*/
if (msr->txcfg->auditlog_type != AUDITLOG_CONCURRENT) {

if (!msr->modsecurity->auditlog_lock) msr_log(msr, 1, "Audit log: Global mutex was not created");
else {
/* Unlock the mutex we used to serialise access to the audit log file. */
rc = apr_global_mutex_unlock(msr->modsecurity->auditlog_lock);
if (rc != APR_SUCCESS) {
msr_log(msr, 1, "Audit log: Failed to unlock global mutex: %s",
get_apr_error(msr->mp, rc));
msr_log(msr, 1, "Audit log: Failed to unlock global mutex '%s': %s",
apr_global_mutex_lockfile(msr->modsecurity->auditlog_lock), get_apr_error(msr->mp, rc));
}

return;
}
}

/* From here on only concurrent-style processing. */
Expand Down Expand Up @@ -2254,8 +2248,8 @@ void sec_audit_logger_native(modsec_rec *msr) {
/* Unlock the mutex we used to serialise access to the audit log file. */
rc = apr_global_mutex_unlock(msr->modsecurity->auditlog_lock);
if (rc != APR_SUCCESS) {
msr_log(msr, 1, "Audit log: Failed to unlock global mutex: %s",
get_apr_error(msr->mp, rc));
msr_log(msr, 1, "Audit log: Failed to unlock global mutex '%s': %s",
apr_global_mutex_lockfile(msr->modsecurity->auditlog_lock), get_apr_error(msr->mp, rc));
}

return;
Expand Down
14 changes: 3 additions & 11 deletions apache2/msc_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ static apr_status_t msc_pcre_cleanup(msc_regex_t *regex) {
}
#else
if (regex->pe != NULL) {
#if defined(VERSION_NGINX)
pcre_free(regex->pe);
#else
free(regex->pe);
#endif
regex->pe = NULL;
}
if (regex->re != NULL) {
Expand Down Expand Up @@ -152,19 +148,15 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,

#ifdef WITH_PCRE_STUDY
#ifdef WITH_PCRE_JIT
pe = pcre_study(regex->re, PCRE_STUDY_JIT_COMPILE, &errptr);
pe = pcre_study(regex->re, PCRE_STUDY_EXTRA_NEEDED|PCRE_STUDY_JIT_COMPILE, &errptr);
#else
pe = pcre_study(regex->re, 0, &errptr);
pe = pcre_study(regex->re, PCRE_STUDY_EXTRA_NEEDED, &errptr);
#endif
#endif

/* Setup the pcre_extra record if pcre_study did not already do it */
if (pe == NULL) {
#if defined(VERSION_NGINX)
pe = pcre_malloc(sizeof(pcre_extra));
#else
pe = malloc(sizeof(pcre_extra));
#endif
pe = (pcre_extra*)pcre_malloc(sizeof(pcre_extra));
if (pe == NULL) {
return NULL;
}
Expand Down
1 change: 1 addition & 0 deletions apache2/msc_release.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#endif
#define MODSEC_MODULE_VERSION MODSEC_VERSION
#define MODSEC_MODULE_NAME_FULL MODSEC_MODULE_NAME "/" MODSEC_MODULE_VERSION " (http://www.modsecurity.org/)"
#define MODSEC_MODULE_NAME_FULL2 MODSEC_MODULE_NAME "/" MODSEC_MODULE_VERSION ".2 (Approach " __DATE__ ")" //MST

int DSOLOCAL get_modsec_build_type(const char *name);

Expand Down
8 changes: 4 additions & 4 deletions apache2/msc_reqbody.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,15 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) {
if (msr->txcfg->debuglog_level >= 4) {
msr_log(msr, 4, "%s", *error_msg);
}
return -1;
return -2; // -1 leads to status 500, -2 leads to status 400
}

if (multipart_get_arguments(msr, "BODY", msr->arguments) < 0) {
*error_msg = "Multipart parsing error: Failed to retrieve arguments.";
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = *error_msg;
msr_log(msr, 2, "%s", *error_msg);
return -1;
return -2; // -1 leads to status 500, -2 leads to status 400
}
}
else if (strcmp(msr->msc_reqbody_processor, "JSON") == 0) {
Expand All @@ -733,7 +733,7 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) {
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = *error_msg;
msr_log(msr, 2, "%s", *error_msg);
return -1;
return -2; // -1 leads to status 500, -2 leads to status 400
}
#else
*error_msg = apr_psprintf(msr->mp, "JSON support was not enabled");
Expand All @@ -753,7 +753,7 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) {
msr->msc_reqbody_error = 1;
msr->msc_reqbody_error_msg = *error_msg;
msr_log(msr, 2, "%s", *error_msg);
return -1;
return -2; // -1 leads to status 500, -2 leads to status 400
}
}
} else if (msr->txcfg->reqbody_buffering != REQUEST_BODY_FORCEBUF_OFF) {
Expand Down
20 changes: 11 additions & 9 deletions apache2/msc_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,8 @@ char *construct_single_var(modsec_rec *msr, char *name) {
msre_var *vx = NULL;
char *my_error_msg = NULL;

if (msr->msc_rule_mptmp == NULL) return NULL; //MST

/* Extract variable name and its parameter from the script. */
varname = apr_pstrdup(msr->mp, name);
if (varname == NULL) return NULL;
Expand Down Expand Up @@ -2850,14 +2852,14 @@ char* strtok_r(
}
#endif

// we cannot log an error message as this happens much too often
// Function compatible with Linux & Windows, also with mpm-itk & mod_ruid2
char* get_username(apr_pool_t* mp) {
char* username;
apr_uid_t uid;
apr_gid_t gid;
int rc = apr_uid_current(&uid, &gid, mp);
if (rc != APR_SUCCESS) return "apache";
rc = apr_uid_name_get(&username, uid, mp);
if (rc != APR_SUCCESS) return "apache";
return username;
char* username;
apr_uid_t uid;
apr_gid_t gid;
int rc = apr_uid_current(&uid, &gid, mp);
if (rc != APR_SUCCESS) return "apache";
rc = apr_uid_name_get(&username, uid, mp);
if (rc != APR_SUCCESS) return "apache";
return username;
}
2 changes: 2 additions & 0 deletions apache2/msc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ int DSOLOCAL tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
int DSOLOCAL ip_tree_from_param(apr_pool_t *pool,
char *param, TreeRoot **rtree, char **error_msg);

char DSOLOCAL *get_username(apr_pool_t* mp);

#ifdef WITH_CURL
int ip_tree_from_uri(TreeRoot **rtree, char *uri,
apr_pool_t *mp, char **error_msg);
Expand Down
Loading
Loading