Skip to content

Commit 23e3cb4

Browse files
author
Marc Stern
committed
Fix for #3255
We don't have to generate a temp name ourselves, it'll be done in apr_global_mutex_create(). We don't have to provide a filename, apr_global_mutex_create() generates one automatically. Moreover, under Unix & Windows, the preferred mechanism won't use a file at all. apr_file_mktemp() cannot be used as it creates the file (at least on FreeBSD). Discussion in Apache mailing list: https://lists.apache.org/thread/ykb26kg4lgcqnldvxwd9p6hv16fy4z9l
1 parent 090e4d3 commit 23e3cb4

File tree

2 files changed

+1
-26
lines changed

2 files changed

+1
-26
lines changed

apache2/modsecurity.c

+1-24
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,7 @@ msc_engine *modsecurity_create(apr_pool_t *mp, int processing_mode) {
123123
}
124124

125125
int acquire_global_lock(apr_global_mutex_t **lock, apr_pool_t *mp) {
126-
apr_status_t rc;
127-
apr_file_t *lock_name;
128-
const char *temp_dir;
129-
const char *filename = NULL;
130-
131-
// get platform temp dir
132-
rc = apr_temp_dir_get(&temp_dir, mp);
133-
if (rc != APR_SUCCESS) {
134-
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, mp, "ModSecurity: Could not get temp dir");
135-
return -1;
136-
}
137-
138-
// use temp path template for lock files
139-
char *path = apr_pstrcat(mp, temp_dir, GLOBAL_LOCK_TEMPLATE, NULL);
140-
141-
rc = apr_file_mktemp(&lock_name, path, 0, mp);
142-
if (rc != APR_SUCCESS) {
143-
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, mp, " ModSecurity: Could not create temporary file for global lock");
144-
return -1;
145-
}
146-
// below func always return APR_SUCCESS
147-
apr_file_name_get(&filename, lock_name);
148-
149-
rc = apr_global_mutex_create(lock, filename, APR_LOCK_DEFAULT, mp);
126+
apr_status_t rc = apr_global_mutex_create(lock, NULL, APR_LOCK_DEFAULT, mp);
150127
if (rc != APR_SUCCESS) {
151128
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, mp, " ModSecurity: Could not create global mutex");
152129
return -1;

apache2/modsecurity.h

-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ typedef struct msc_parm msc_parm;
135135

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

138-
#define GLOBAL_LOCK_TEMPLATE "/modsec-lock-tmp.XXXXXX"
139-
140138
extern DSOLOCAL char *new_server_signature;
141139
extern DSOLOCAL char *real_server_signature;
142140
extern DSOLOCAL char *chroot_dir;

0 commit comments

Comments
 (0)