Skip to content

Commit b90fa2d

Browse files
blappmFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Use tempfiles for apr_global_mutex_create() to fix segfaults with Apache 2.2.
Call modsecurity_init() for the first invocation too.
1 parent f5dbaae commit b90fa2d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

apache2/modsecurity.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
133133
curl_global_init(CURL_GLOBAL_ALL);
134134
#endif
135135
/* Serial audit log mutext */
136-
rc = apr_global_mutex_create(&msce->auditlog_lock, NULL, APR_LOCK_DEFAULT, mp);
136+
tmpnam(auditlog_lock_name);
137+
rc = apr_global_mutex_create(&msce->auditlog_lock, auditlog_lock_name, APR_LOCK_DEFAULT, mp);
137138
if (rc != APR_SUCCESS) {
138139
//ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "mod_security: Could not create modsec_auditlog_lock");
139140
//return HTTP_INTERNAL_SERVER_ERROR;
@@ -154,7 +155,8 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
154155
}
155156
#endif /* SET_MUTEX_PERMS */
156157

157-
rc = apr_global_mutex_create(&msce->geo_lock, NULL, APR_LOCK_DEFAULT, mp);
158+
tmpnam(geo_lock_name);
159+
rc = apr_global_mutex_create(&msce->geo_lock, geo_lock_name, APR_LOCK_DEFAULT, mp);
158160
if (rc != APR_SUCCESS) {
159161
return -1;
160162
}
@@ -171,7 +173,8 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
171173
#endif /* SET_MUTEX_PERMS */
172174

173175
#ifdef GLOBAL_COLLECTION_LOCK
174-
rc = apr_global_mutex_create(&msce->dbm_lock, NULL, APR_LOCK_DEFAULT, mp);
176+
tmpnam(dbm_lock_name);
177+
rc = apr_global_mutex_create(&msce->dbm_lock, dbm_lock_name, APR_LOCK_DEFAULT, mp);
175178
if (rc != APR_SUCCESS) {
176179
return -1;
177180
}

apache2/modsecurity.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ typedef struct msc_parm msc_parm;
133133

134134
#define FATAL_ERROR "ModSecurity: Fatal error (memory allocation or unexpected internal error)!"
135135

136+
static char auditlog_lock_name[L_tmpnam];
137+
static char geo_lock_name[L_tmpnam];
138+
#ifdef GLOBAL_COLLECTION_LOCK
139+
static char dbm_lock_name[L_tmpnam];
140+
#endif
141+
136142
extern DSOLOCAL char *new_server_signature;
137143
extern DSOLOCAL char *real_server_signature;
138144
extern DSOLOCAL char *chroot_dir;

0 commit comments

Comments
 (0)