Skip to content

Passing address of lock instead of lock in acquire_global_lock() #3176

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 10 commits into from
Closed
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
35 changes: 15 additions & 20 deletions apache2/modsecurity.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ msc_engine *modsecurity_create(apr_pool_t *mp, int processing_mode) {
return msce;
}

int acquire_global_lock(apr_global_mutex_t *lock, apr_pool_t *mp) {
int acquire_global_lock(apr_global_mutex_t **lock, apr_pool_t *mp) {
apr_status_t rc;
apr_file_t *lock_name;
const char *temp_dir;
Expand All @@ -146,22 +146,23 @@ int acquire_global_lock(apr_global_mutex_t *lock, apr_pool_t *mp) {
// below func always return APR_SUCCESS
apr_file_name_get(&filename, lock_name);

rc = apr_global_mutex_create(&lock, filename, APR_LOCK_DEFAULT, mp);
rc = apr_global_mutex_create(lock, filename, APR_LOCK_DEFAULT, mp);
if (rc != APR_SUCCESS) {
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, NULL, " ModSecurity: Could not create global mutex");
return -1;
}
#if !defined(MSC_TEST)
#ifdef __SET_MUTEX_PERMS
#if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
rc = ap_unixd_set_global_mutex_perms(lock);
#else
rc = unixd_set_global_mutex_perms(lock);
#endif
# ifdef __SET_MUTEX_PERMS
# if AP_SERVER_MAJORVERSION_NUMBER > 1 && AP_SERVER_MINORVERSION_NUMBER > 2
rc = ap_unixd_set_global_mutex_perms(*lock);
# else
rc = unixd_set_global_mutex_perms(*lock);
# endif
if (rc != APR_SUCCESS) {
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, NULL, " ModSecurity: Could not set permissions on global mutex");
return -1;
}
#endif /* SET_MUTEX_PERMS */
# endif /* SET_MUTEX_PERMS */
#endif /* MSC_TEST */
return APR_SUCCESS;
}
Expand Down Expand Up @@ -189,21 +190,15 @@ int modsecurity_init(msc_engine *msce, apr_pool_t *mp) {
curl_global_init(CURL_GLOBAL_ALL);
#endif
/* Serial audit log mutex */
rc = acquire_global_lock(msce->auditlog_lock, mp);
if (rc != APR_SUCCESS) {
return -1;
}
rc = acquire_global_lock(&msce->auditlog_lock, mp);
if (rc != APR_SUCCESS) return -1;

rc = acquire_global_lock(msce->geo_lock, mp);
if (rc != APR_SUCCESS) {
return -1;
}
rc = acquire_global_lock(&msce->geo_lock, mp);
if (rc != APR_SUCCESS) return -1;

#ifdef GLOBAL_COLLECTION_LOCK
rc = acquire_global_lock(&msce->dbm_lock, mp);
if (rc != APR_SUCCESS) {
return -1;
}
if (rc != APR_SUCCESS) return -1;
#endif /* GLOBAL_COLLECTION_LOCK */

return 1;
Expand Down
2 changes: 1 addition & 1 deletion apache2/modsecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ struct msc_parm {
};

/* Reusable functions */
int acquire_global_lock(apr_global_mutex_t *lock, apr_pool_t *mp);
int acquire_global_lock(apr_global_mutex_t **lock, apr_pool_t *mp);

/* Engine functions */

Expand Down
Loading