Skip to content
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

V2/refactor/default pcre2 #3345

Open
wants to merge 3 commits into
base: v2/master
Choose a base branch
from
Open
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
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
*.o
*.lo
*.la
**/Makefile
**/Makefile.in
.deps
.libs
configure
configure~
config.log
config.status
aclocal.m4
libtool
.dirstamp
config.guess
config.sub
apache2/modsecurity_config_auto.h
apache2/modsecurity_config_auto.h.in
apache2/stamp-h1
build/apxs-wrapper
build/ar-lib
build/compile
build/depcomp
build/install-sh
build/libtool.m4
build/ltmain.sh
build/ltoptions.m4
build/ltsugar.m4
build/ltversion.m4
build/lt~obsolete.m4
build/missing
build/test-driver
mlogc/mlogc
mlogc/mlogc-batch-load.pl
tests/csv_rx-pm.pl
tests/gen_rx-pm.pl
tests/regression/misc/40-secRemoteRules.t
tests/regression/misc/50-ipmatchfromfile-external.t
tests/regression/misc/60-pmfromfile-external.t
tests/regression/server_root/conf/httpd.conf
tests/run-regression-tests.pl
tests/run-unit-tests.pl
tools/rules-updater.pl

2 changes: 1 addition & 1 deletion apache2/apache2_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ static const char *cmd_audit_log_relevant_status(cmd_parms *cmd, void *_dcfg,
{
directory_config *dcfg = _dcfg;

#ifdef WITH_PCRE2
#ifndef WITH_PCRE
dcfg->auditlog_relevant_regex = msc_pregcomp(cmd->pool, p1, PCRE2_DOTALL, NULL, NULL);
#else
dcfg->auditlog_relevant_regex = msc_pregcomp(cmd->pool, p1, PCRE_DOTALL, NULL, NULL);
Expand Down
4 changes: 2 additions & 2 deletions apache2/mod_security2.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void version(apr_pool_t *mp) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "ModSecurity: Loaded APR do not match with compiled!");
}

#ifdef WITH_PCRE2
#ifndef WITH_PCRE
pcre_vrs = apr_psprintf(mp,"%d.%d ", PCRE2_MAJOR, PCRE2_MINOR);
pcre_loaded_vrs = pcre2_loaded_vrs_buffer;
pcre2_config(PCRE2_CONFIG_VERSION, pcre2_loaded_vrs_buffer);
Expand All @@ -126,7 +126,7 @@ static void version(apr_pool_t *mp) {
#endif

ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
"ModSecurity: PCRE2 compiled version=\"%s\"; "
#else
"ModSecurity: PCRE compiled version=\"%s\"; "
Expand Down
4 changes: 2 additions & 2 deletions apache2/modsecurity.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,14 @@ static int is_response_status_relevant(modsec_rec *msr, int status) {

rc = msc_regexec(msr->txcfg->auditlog_relevant_regex, buf, strlen(buf), &my_error_msg);
if (rc >= 0) return 1;
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if (rc == PCRE2_ERROR_NOMATCH) return 0;
#else
if (rc == PCRE_ERROR_NOMATCH) return 0;
#endif

msr_log(msr, 1, "Regex processing failed (rc %d): %s", rc, my_error_msg);

return 0;
}

Expand Down
20 changes: 10 additions & 10 deletions apache2/msc_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
case HASH_URL_HREF_HASH_RX:
if(em[i]->type == HASH_URL_HREF_HASH_RX) {
rc = msc_regexec_capture(em[i]->param_data, link, strlen(link), ovector, 30, &my_error_msg);
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if ((rc == PCRE2_ERROR_MATCHLIMIT) || (rc == PCRE2_ERROR_RECURSIONLIMIT)) {
#else
if ((rc == PCRE_ERROR_MATCHLIMIT) || (rc == PCRE_ERROR_RECURSIONLIMIT)) {
Expand Down Expand Up @@ -419,7 +419,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
msr_log(msr, 4, "%s.", error_msg);
return -1;
}
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if (rc != PCRE2_ERROR_NOMATCH) { /* Match. */
#else
if (rc != PCRE_ERROR_NOMATCH) { /* Match. */
Expand Down Expand Up @@ -449,7 +449,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
case HASH_URL_FACTION_HASH_RX:
if(em[i]->type == HASH_URL_FACTION_HASH_RX) {
rc = msc_regexec_capture(em[i]->param_data, link, strlen(link), ovector, 30, &my_error_msg);
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if ((rc == PCRE2_ERROR_MATCHLIMIT) || (rc == PCRE2_ERROR_RECURSIONLIMIT)) {
#else
if ((rc == PCRE_ERROR_MATCHLIMIT) || (rc == PCRE_ERROR_RECURSIONLIMIT)) {
Expand Down Expand Up @@ -482,7 +482,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
msr_log(msr, 4, "%s.", error_msg);
return -1;
}
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if (rc != PCRE2_ERROR_NOMATCH) { /* Match. */
#else
if (rc != PCRE_ERROR_NOMATCH) { /* Match. */
Expand Down Expand Up @@ -512,7 +512,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
case HASH_URL_LOCATION_HASH_RX:
if(em[i]->type == HASH_URL_LOCATION_HASH_RX) {
rc = msc_regexec_capture(em[i]->param_data, link, strlen(link), ovector, 30, &my_error_msg);
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if ((rc == PCRE2_ERROR_MATCHLIMIT) || (rc == PCRE2_ERROR_RECURSIONLIMIT)) {
#else
if ((rc == PCRE_ERROR_MATCHLIMIT) || (rc == PCRE_ERROR_RECURSIONLIMIT)) {
Expand Down Expand Up @@ -545,7 +545,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
msr_log(msr, 4, "%s.", error_msg);
return -1;
}
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if (rc != PCRE2_ERROR_NOMATCH) { /* Match. */
#else
if (rc != PCRE_ERROR_NOMATCH) { /* Match. */
Expand Down Expand Up @@ -575,7 +575,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
case HASH_URL_IFRAMESRC_HASH_RX:
if(em[i]->type == HASH_URL_IFRAMESRC_HASH_RX) {
rc = msc_regexec_capture(em[i]->param_data, link, strlen(link), ovector, 30, &my_error_msg);
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if ((rc == PCRE2_ERROR_MATCHLIMIT) || (rc == PCRE2_ERROR_RECURSIONLIMIT)) {
#else
if ((rc == PCRE_ERROR_MATCHLIMIT) || (rc == PCRE_ERROR_RECURSIONLIMIT)) {
Expand Down Expand Up @@ -608,7 +608,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
msr_log(msr, 4, "%s.", error_msg);
return -1;
}
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if (rc != PCRE2_ERROR_NOMATCH) { /* Match. */
#else
if (rc != PCRE_ERROR_NOMATCH) { /* Match. */
Expand Down Expand Up @@ -638,7 +638,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
case HASH_URL_FRAMESRC_HASH_RX:
if(em[i]->type == HASH_URL_FRAMESRC_HASH_RX) {
rc = msc_regexec_capture(em[i]->param_data, link, strlen(link), ovector, 30, &my_error_msg);
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if ((rc == PCRE2_ERROR_MATCHLIMIT) || (rc == PCRE2_ERROR_RECURSIONLIMIT)) {
#else
if ((rc == PCRE_ERROR_MATCHLIMIT) || (rc == PCRE_ERROR_RECURSIONLIMIT)) {
Expand Down Expand Up @@ -671,7 +671,7 @@ int do_hash_method(modsec_rec *msr, char *link, int type) {
msr_log(msr, 4, "%s.", error_msg);
return -1;
}
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if (rc != PCRE2_ERROR_NOMATCH) { /* Match. */
#else
if (rc != PCRE_ERROR_NOMATCH) { /* Match. */
Expand Down
12 changes: 6 additions & 6 deletions apache2/msc_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
static apr_status_t msc_pcre_cleanup(msc_regex_t *regex) {
if (regex != NULL) {
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
if (regex->match_context != NULL) {
pcre2_match_context_free(regex->match_context);
regex->match_context = NULL;
Expand Down Expand Up @@ -59,7 +59,7 @@ static apr_status_t msc_pcre_cleanup(msc_regex_t *regex) {
void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,
const char **_errptr, int *_erroffset,
int match_limit, int match_limit_recursion)
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
{
msc_regex_t *regex = NULL;
PCRE2_SPTR pcre2_pattern;
Expand Down Expand Up @@ -132,7 +132,7 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,

return regex;
}
#else /* not WITH_PCRE2 */
#else /* not ifndef WITH_PCRE */
{
const char *errptr = NULL;
int erroffset;
Expand Down Expand Up @@ -216,7 +216,7 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,

return regex;
}
#endif /* WITH_PCRE2 */
#endif /* ifndef WITH_PCRE */

/**
* Compiles the provided regular expression pattern. Calls msc_pregcomp_ex()
Expand All @@ -239,7 +239,7 @@ int msc_regexec_ex(msc_regex_t *regex, const char *s, unsigned int slen,
if (error_msg == NULL) return -1000; /* To differentiate from PCRE as it already uses -1. */
*error_msg = NULL;

#ifdef WITH_PCRE2
#ifndef WITH_PCRE
{
PCRE2_SPTR pcre2_s;
int pcre2_ret;
Expand Down Expand Up @@ -319,7 +319,7 @@ int msc_regexec(msc_regex_t *regex, const char *s, unsigned int slen,
*/
int msc_fullinfo(msc_regex_t *regex, int what, void *where)
{
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
return pcre2_pattern_info(regex->re, (uint32_t)what, where);
#else
return pcre_fullinfo(regex->re, regex->pe, what, where);
Expand Down
6 changes: 3 additions & 3 deletions apache2/msc_pcre.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

typedef struct msc_regex_t msc_regex_t;

#ifdef WITH_PCRE2
#ifndef WITH_PCRE
#define PCRE2_CODE_UNIT_WIDTH 8
#include "pcre2.h"
#else
#include "pcre.h"
#endif

#ifndef WITH_PCRE2
#ifdef WITH_PCRE

#ifndef PCRE_ERROR_MATCHLIMIT
/* Define for compile, but not valid in this version of PCRE. */
Expand All @@ -42,7 +42,7 @@ typedef struct msc_regex_t msc_regex_t;
#include "modsecurity.h"

struct msc_regex_t {
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
pcre2_code *re;
pcre2_match_context *match_context;
#ifdef WITH_PCRE_JIT
Expand Down
2 changes: 1 addition & 1 deletion apache2/msc_status_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ int DSOLOCAL msc_beacon_string (char *beacon_string, int beacon_string_max_len)

apr = APR_VERSION_STRING;
apr_loaded = apr_version_string();
#ifdef WITH_PCRE2
#ifndef WITH_PCRE
apr_snprintf(pcre, 7, "%d.%d", PCRE2_MAJOR, PCRE2_MINOR);
pcre_loaded = ""; /* complete this if/when status reactivated */
#else
Expand Down
Loading