Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 apache2/apache2.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,7 @@ char DSOLOCAL *format_error_log_message(apr_pool_t *mp, error_message_t *em);
const DSOLOCAL char *get_response_protocol(request_rec *r);


void DSOLOCAL modsec_close_piped_log_read_fds(void);

#endif

44 changes: 44 additions & 0 deletions apache2/apache2_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
char *my_error_msg = NULL;

int rc = msc_regexec(exceptions[j]->param_data,
rule->actionset->msg, strlen(rule->actionset->msg),

Check warning on line 217 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'function': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 217 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'function': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
&my_error_msg);
if (rc >= 0) copy--;
}
Expand All @@ -234,7 +234,7 @@
if(strcmp("tag", action->metadata->name) == 0) {

int rc = msc_regexec(exceptions[j]->param_data,
action->param, strlen(action->param),

Check warning on line 237 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'function': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 237 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'function': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
&my_error_msg);
if (rc >= 0) copy--;
}
Expand Down Expand Up @@ -754,7 +754,7 @@
/* Hash */
if (dcfg->hash_is_enabled == HASH_ENABLED) {
if (dcfg->crypto_key == NOT_SET_P) dcfg->crypto_key = getkey(dcfg->mp);
if (dcfg->crypto_key_len == NOT_SET) dcfg->crypto_key_len = strlen(dcfg->crypto_key);

Check warning on line 757 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'=': conversion from 'size_t' to 'int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 757 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'=': conversion from 'size_t' to 'int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
} else {
if (dcfg->crypto_key == NOT_SET_P) dcfg->crypto_key = "";
if (dcfg->crypto_key_len == NOT_SET) dcfg->crypto_key_len = 0;
Expand Down Expand Up @@ -1222,11 +1222,11 @@
assert(p1 != NULL);
directory_config *dcfg = _dcfg;

if (strcasecmp(p1, "On") == 0) dcfg->auditlog_flag = AUDITLOG_ON;

Check warning on line 1225 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1225 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1225 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1225 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
else
if (strcasecmp(p1, "Off") == 0) dcfg->auditlog_flag = AUDITLOG_OFF;

Check warning on line 1227 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1227 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1227 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1227 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
else
if (strcasecmp(p1, "RelevantOnly") == 0) dcfg->auditlog_flag = AUDITLOG_RELEVANT;

Check warning on line 1229 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1229 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1229 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1229 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
else
return (const char *)apr_psprintf(cmd->pool,
"ModSecurity: Unrecognised parameter value for SecAuditEngine: %s", p1);
Expand All @@ -1234,6 +1234,47 @@
return NULL;
}

/**
* Piped logs are opened while the configuration is read, so unlike the
* ones httpd opens in its open_logs hook their read ends are not on the
* list httpd closes in every child. A child that keeps the read end of a
* pipe can never see EPIPE when the logger dies, and blocks in write()
* for ever after a graceful restart (#2822). Remember the read ends here
* and close them from the child_init hook.
*/
static apr_array_header_t *piped_log_read_fds = NULL;

static apr_status_t piped_log_read_fds_cleanup(void *data) {
piped_log_read_fds = NULL;
return APR_SUCCESS;
}

static void piped_log_remember_read_fd(apr_pool_t *p, piped_log *pl) {
apr_file_t *fd = ap_piped_log_read_fd(pl);

if (fd == NULL) return;

if (piped_log_read_fds == NULL) {
piped_log_read_fds = apr_array_make(p, 4, sizeof(apr_file_t *));
apr_pool_cleanup_register(p, NULL, piped_log_read_fds_cleanup,
apr_pool_cleanup_null);
}
*(apr_file_t **)apr_array_push(piped_log_read_fds) = fd;
}

void modsec_close_piped_log_read_fds(void) {
int i;

if (piped_log_read_fds == NULL) return;

for (i = 0; i < piped_log_read_fds->nelts; i++) {
apr_file_t *fd = ((apr_file_t **)piped_log_read_fds->elts)[i];
if (fd != NULL) {
apr_file_close(fd);
}
}
}

static const char *cmd_audit_log(cmd_parms *cmd, void *_dcfg, const char *p1)
{
assert(cmd != NULL);
Expand All @@ -1253,6 +1294,7 @@
pipe_name);
}
dcfg->auditlog_fd = ap_piped_log_write_fd(pipe_log);
piped_log_remember_read_fd(cmd->pool, pipe_log);
}
else {
const char *file_name = ap_server_root_relative(cmd->pool, dcfg->auditlog_name);
Expand Down Expand Up @@ -1297,6 +1339,7 @@
pipe_name);
}
dcfg->auditlog2_fd = ap_piped_log_write_fd(pipe_log);
piped_log_remember_read_fd(cmd->pool, pipe_log);
}
else {
const char *file_name = ap_server_root_relative(cmd->pool, dcfg->auditlog2_name);
Expand Down Expand Up @@ -1362,9 +1405,9 @@
assert(p1 != NULL);
directory_config *dcfg = _dcfg;

if (strcasecmp(p1, "Serial") == 0) dcfg->auditlog_type = AUDITLOG_SERIAL;

Check warning on line 1408 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1408 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1408 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1408 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
else
if (strcasecmp(p1, "Concurrent") == 0) dcfg->auditlog_type = AUDITLOG_CONCURRENT;

Check warning on line 1410 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1410 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
else
return (const char *)apr_psprintf(cmd->pool,
"ModSecurity: Unrecognised parameter value for SecAuditLogType: %s", p1);
Expand All @@ -1381,9 +1424,9 @@
assert(p1 != NULL);
directory_config *dcfg = _dcfg;

if (strcasecmp(p1, "JSON") == 0) dcfg->auditlog_format = AUDITLOGFORMAT_JSON;

Check warning on line 1427 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1427 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
else
if (strcasecmp(p1, "Native") == 0) dcfg->auditlog_format = AUDITLOGFORMAT_NATIVE;

Check warning on line 1429 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1429 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
else
return (const char *)apr_psprintf(cmd->pool,
"ModSecurity: Unrecognised parameter value for SecAuditLogFormat: %s", p1);
Expand All @@ -1405,7 +1448,7 @@
}
directory_config *dcfg = (directory_config *)_dcfg;

if (strcasecmp(p1, "default") == 0) {

Check warning on line 1451 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1451 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
dcfg->auditlog_dirperms = NOT_SET;
}
else {
Expand Down Expand Up @@ -1433,7 +1476,7 @@
}
directory_config *dcfg = (directory_config *)_dcfg;

if (strcasecmp(p1, "default") == 0) {

Check warning on line 1479 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1479 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'stricmp': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _stricmp. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
dcfg->auditlog_fileperms = NOT_SET;
}
else {
Expand Down Expand Up @@ -1491,7 +1534,7 @@

chroot_dir = (char *)p1;

if (getcwd(cwd, 1024) == NULL) {

Check warning on line 1537 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, RelWithDebInfo)

'getcwd': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _getcwd. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1537 in apache2/apache2_config.c

View workflow job for this annotation

GitHub Actions / build (x86, Release)

'getcwd': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _getcwd. See online help for details. [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
return "ModSecurity: Failed to get the current working directory";
}

Expand Down Expand Up @@ -1746,6 +1789,7 @@
pipe_name);
}
guardianlog_fd = ap_piped_log_write_fd(pipe_log);
piped_log_remember_read_fd(cmd->pool, pipe_log);
}
else {
const char *file_name = ap_server_root_relative(cmd->pool, guardianlog_name);
Expand Down
2 changes: 2 additions & 0 deletions apache2/mod_security2.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
msc_string *var = (msc_string *)apr_pcalloc(msr->mp, sizeof(msc_string));

var->value = (char *)actionset->intercept_pause;
var->value_len = strlen(actionset->intercept_pause);

Check warning on line 199 in apache2/mod_security2.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 199 in apache2/mod_security2.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
expand_macros(msr, var, NULL, msr->mp);

pause = atoi(var->value);
Expand Down Expand Up @@ -343,7 +343,7 @@
msc_string *var = (msc_string *)apr_pcalloc(msr->mp, sizeof(msc_string));

var->value = (char *)actionset->intercept_uri;
var->value_len = strlen(actionset->intercept_uri);

Check warning on line 346 in apache2/mod_security2.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 346 in apache2/mod_security2.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
expand_macros(msr, var, NULL, msr->mp);

apr_table_setn(msr->r->headers_out, "Location", var->value);
Expand Down Expand Up @@ -844,6 +844,8 @@
* Initialisation performed for every new child process.
*/
static void hook_child_init(apr_pool_t *mp, server_rec *s) {
/* Drop the read ends of our piped logs, as httpd does for its own. */
modsec_close_piped_log_read_fds();
modsecurity_child_init(modsecurity);
}

Expand Down Expand Up @@ -1217,7 +1219,7 @@
}
}

limit = limit - strlen(str2) - 5;

Check warning on line 1222 in apache2/mod_security2.c

View workflow job for this annotation

GitHub Actions / build (x64, Release)

'=': conversion from 'size_t' to 'int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]

Check warning on line 1222 in apache2/mod_security2.c

View workflow job for this annotation

GitHub Actions / build (x64, RelWithDebInfo)

'=': conversion from 'size_t' to 'int', possible loss of data [D:\a\ModSecurity\ModSecurity\iis\build\modsecurityiis.vcxproj]
if (limit <= 0) {
msr_log(msr, 1, "Audit Log: Atomic PIPE write buffer too small: %d", PIPE_BUF);
return;
Expand Down
Loading