Skip to content

Commit 824e523

Browse files
authored
Merge pull request #3188 from marcstern/v2/pr/acquire_global_lock
Passing address of lock instead of lock in acquire_global_lock()
2 parents 28b6e1d + ca593a4 commit 824e523

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

apache2/modsecurity.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ msc_engine *modsecurity_create(apr_pool_t *mp, int processing_mode) {
122122
return msce;
123123
}
124124

125-
int acquire_global_lock(apr_global_mutex_t *lock, apr_pool_t *mp) {
125+
int acquire_global_lock(apr_global_mutex_t **lock, apr_pool_t *mp) {
126126
apr_status_t rc;
127127
apr_file_t *lock_name;
128128
const char *temp_dir;
@@ -146,19 +146,20 @@ int acquire_global_lock(apr_global_mutex_t *lock, apr_pool_t *mp) {
146146
// below func always return APR_SUCCESS
147147
apr_file_name_get(&filename, lock_name);
148148

149-
rc = apr_global_mutex_create(&lock, filename, APR_LOCK_DEFAULT, mp);
149+
rc = apr_global_mutex_create(lock, filename, APR_LOCK_DEFAULT, mp);
150150
if (rc != APR_SUCCESS) {
151151
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, NULL, " ModSecurity: Could not create global mutex");
152152
return -1;
153153
}
154154
#if !defined(MSC_TEST)
155155
#ifdef __SET_MUTEX_PERMS
156156
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
157-
rc = ap_unixd_set_global_mutex_perms(lock);
157+
rc = ap_unixd_set_global_mutex_perms(*lock);
158158
#else
159-
rc = unixd_set_global_mutex_perms(lock);
159+
rc = unixd_set_global_mutex_perms(*lock);
160160
#endif
161161
if (rc != APR_SUCCESS) {
162+
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, NULL, " ModSecurity: Could not set permissions on global mutex");
162163
return -1;
163164
}
164165
#endif /* SET_MUTEX_PERMS */
@@ -189,21 +190,15 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
189190
curl_global_init(CURL_GLOBAL_ALL);
190191
#endif
191192
/* Serial audit log mutex */
192-
rc = acquire_global_lock(msce->auditlog_lock, mp);
193-
if (rc != APR_SUCCESS) {
194-
return -1;
195-
}
193+
rc = acquire_global_lock(&msce->auditlog_lock, mp);
194+
if (rc != APR_SUCCESS) return -1;
196195

197-
rc = acquire_global_lock(msce->geo_lock, mp);
198-
if (rc != APR_SUCCESS) {
199-
return -1;
200-
}
196+
rc = acquire_global_lock(&msce->geo_lock, mp);
197+
if (rc != APR_SUCCESS) return -1;
201198

202199
#ifdef GLOBAL_COLLECTION_LOCK
203200
rc = acquire_global_lock(&msce->dbm_lock, mp);
204-
if (rc != APR_SUCCESS) {
205-
return -1;
206-
}
201+
if (rc != APR_SUCCESS) return -1;
207202
#endif /* GLOBAL_COLLECTION_LOCK */
208203

209204
return 1;

apache2/modsecurity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ struct msc_parm {
706706
};
707707

708708
/* Reusable functions */
709-
int acquire_global_lock(apr_global_mutex_t *lock, apr_pool_t *mp);
709+
int acquire_global_lock(apr_global_mutex_t **lock, apr_pool_t *mp);
710710

711711
/* Engine functions */
712712

0 commit comments

Comments
 (0)