Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7d786b3

Browse files
author
Felipe Zimmerle
committedSep 26, 2017
Makes pm mutex optional via configuration flag
1 parent 119a6fc commit 7d786b3

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed
 

‎configure.ac

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ AC_ARG_ENABLE(parser-generation,
248248
[buildParser=false]
249249
)
250250

251+
# Mutex
252+
AC_ARG_ENABLE(mutex-on-pm,
253+
[AC_HELP_STRING([--enable-mutex-on-pm],[Treats pm operations as a critical section])],
254+
255+
[case "${enableval}" in
256+
yes) mutexPm=true ;;
257+
no) mutexPm=false ;;
258+
*) AC_MSG_ERROR(bad value ${enableval} for --enable-mutex-on-pm) ;;
259+
esac],
260+
261+
[mutexPm=false]
262+
)
263+
if test "$mutexPm" == "true"; then
264+
MODSEC_MUTEX_ON_PM="-DMUTEX_ON_PM=1"
265+
AC_SUBST(MODSEC_MUTEX_ON_PM)
266+
fi
267+
251268

252269
if test $buildParser = true; then
253270
AC_PROG_YACC
@@ -287,6 +304,7 @@ fi
287304

288305
AM_CONDITIONAL([EXAMPLES], [test $buildExamples = true])
289306
AM_CONDITIONAL([BUILD_PARSER], [test $buildParser = true])
307+
AM_CONDITIONAL([USE_MUTEX_ON_PM], [test $mutexPm = true])
290308

291309

292310
# General link options
@@ -494,12 +512,20 @@ if test "$buildExamples" = "true"; then
494512
else
495513
echo " + library examples ....disabled"
496514
fi
515+
497516
if test "$buildParser" = "true"; then
498517
echo " + Building parser ....enabled"
499518
else
500519
echo " + Building parser ....disabled"
501520
fi
502521

522+
if test "$mutexPm" = "true"; then
523+
echo " + Treating pm operations as critical section ....enabled"
524+
else
525+
echo " + Treating pm operations as critical section ....disabled"
526+
fi
527+
528+
503529
echo " "
504530

505531

‎src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ libmodsecurity_la_CPPFLAGS = \
293293
$(GEOIP_CFLAGS) \
294294
$(GLOBAL_CPPFLAGS) \
295295
$(MODSEC_NO_LOGS) \
296+
$(MODSEC_MUTEX_ON_PM) \
296297
$(YAJL_CFLAGS) \
297298
$(LMDB_CFLAGS) \
298299
$(PCRE_CFLAGS) \

‎src/operators/pm.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ Pm::~Pm() {
4040

4141
free(m_p);
4242
m_p = NULL;
43+
#ifdef MODSEC_MUTEX_ON_PM
4344
pthread_mutex_destroy(&m_lock);
45+
#endif
4446
}
4547

4648

@@ -87,9 +89,13 @@ bool Pm::evaluate(Transaction *transaction, Rule *rule,
8789
pt.parser = m_p;
8890
pt.ptr = NULL;
8991
const char *match = NULL;
92+
#ifdef MODSEC_MUTEX_ON_PM
9093
pthread_mutex_lock(&m_lock);
94+
#endif
9195
rc = acmp_process_quick(&pt, &match, input.c_str(), input.length());
96+
#ifdef MODSEC_MUTEX_ON_PM
9297
pthread_mutex_unlock(&m_lock);
98+
#endif
9399
bool capture = rule && rule->getActionsByName("capture").size() > 0;
94100

95101
if (rc > 0 && transaction) {
@@ -116,8 +122,9 @@ bool Pm::init(const std::string &file, std::string *error) {
116122
std::istringstream *iss;
117123
const char *err = NULL;
118124

125+
#ifdef MODSEC_MUTEX_ON_PM
119126
pthread_mutex_init(&m_lock, NULL);
120-
127+
#endif
121128
char *content = parse_pm_content(m_param.c_str(), m_param.length(), &err);
122129
if (content == NULL) {
123130
iss = new std::istringstream(m_param);

‎src/operators/pm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ class Pm : public Operator {
5656
protected:
5757
ACMP *m_p;
5858

59+
#ifdef MODSEC_MUTEX_ON_PM
5960
private:
6061
pthread_mutex_t m_lock;
62+
#endif
6163
};
6264

6365

0 commit comments

Comments
 (0)
Please sign in to comment.