From cd730842da7898fa4cd1d2ff6545a7f98d7d5ae8 Mon Sep 17 00:00:00 2001 From: b1v1r Date: Fri, 5 Feb 2010 18:23:18 +0000 Subject: [PATCH] Fixed compiles using PCRE pre v6.5 (ie Apache includes 5.0) --- apache2/msc_pcre.c | 21 ++++++++++++++++++--- apache2/msc_pcre.h | 11 +++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/apache2/msc_pcre.c b/apache2/msc_pcre.c index d11db7f8..b8a5a012 100644 --- a/apache2/msc_pcre.c +++ b/apache2/msc_pcre.c @@ -78,28 +78,43 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options, memset(pe, 0, sizeof(pcre_extra)); } - /* Set some PCRE limits */ +#ifdef PCRE_EXTRA_MATCH_LIMIT + /* If match limit is available, then use it */ + + /* Use ModSecurity runtime defaults */ if (match_limit > 0) { pe->match_limit = match_limit; pe->flags |= PCRE_EXTRA_MATCH_LIMIT; } #ifdef MODSEC_PCRE_MATCH_LIMIT + /* Default to ModSecurity compiled defaults */ else { pe->match_limit = MODSEC_PCRE_MATCH_LIMIT; pe->flags |= PCRE_EXTRA_MATCH_LIMIT; } -#endif +#endif /* MODSEC_PCRE_MATCH_LIMIT */ +#else +#warning This PCRE version does not support match limits! Upgrade to at least PCRE v6.5. +#endif /* PCRE_EXTRA_MATCH_LIMIT */ +#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION + /* If match limit recursion is available, then use it */ + + /* Use ModSecurity runtime defaults */ if (match_limit_recursion > 0) { pe->match_limit_recursion = match_limit_recursion; pe->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; } #ifdef MODSEC_PCRE_MATCH_LIMIT_RECURSION + /* Default to ModSecurity compiled defaults */ else { pe->match_limit_recursion = MODSEC_PCRE_MATCH_LIMIT_RECURSION; pe->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; } -#endif +#endif /* MODSEC_PCRE_MATCH_LIMIT_RECURSION */ +#else +#warning This PCRE version does not support match recursion limits! Upgrade to at least PCRE v6.5. +#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */ regex->pe = pe; diff --git a/apache2/msc_pcre.h b/apache2/msc_pcre.h index dd6a7ece..63a8f8c5 100644 --- a/apache2/msc_pcre.h +++ b/apache2/msc_pcre.h @@ -22,6 +22,17 @@ typedef struct msc_regex_t msc_regex_t; #include "pcre.h" + +#ifndef PCRE_ERROR_MATCHLIMIT +/* Define for compile, but not valid in this version of PCRE. */ +#define PCRE_ERROR_MATCHLIMIT (-8) +#endif /* PCRE_ERROR_MATCHLIMIT */ + +#ifndef PCRE_ERROR_RECURSIONLIMIT +/* Define for compile, but not valid in this version of PCRE. */ +#define PCRE_ERROR_RECURSIONLIMIT (-21) +#endif /* PCRE_ERROR_RECURSIONLIMIT */ + #include "apr_general.h" #include "modsecurity.h"