From df50a5ffda4775ce8ec1e7d2b6199f3fe4d16cc6 Mon Sep 17 00:00:00 2001 From: Kevin Lin Date: Tue, 16 Sep 2014 11:20:39 -0400 Subject: [PATCH] dconf: added pcre options and pcre global dconf: fixed issue in module support report --- libclamav/dconf.c | 4 +++- libclamav/dconf.h | 2 ++ libclamav/matcher-pcre.c | 19 ++++++++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libclamav/dconf.c b/libclamav/dconf.c index 4483de434..40fe46cf0 100644 --- a/libclamav/dconf.c +++ b/libclamav/dconf.c @@ -137,6 +137,8 @@ static struct dconf_module modules[] = { { "STATS", "PESECTION DISABLED", DCONF_STATS_PE_SECTION_DISABLED, 0 }, { "PCRE", "SUPPORT", PCRE_CONF_SUPPORT, 1 }, + { "PCRE", "OPTIONS", PCRE_CONF_OPTIONS, 1 }, + { "PCRE", "GLOBAL", PCRE_CONF_GLOBAL, 1 }, { NULL, NULL, 0, 0 } }; @@ -303,7 +305,7 @@ void cli_dconf_print(struct cli_dconf *dconf) } else if (!strcmp(modules[i].mname, "PCRE")) { if (!pcre) { cli_dbgmsg("Module PCRE %s\n", dconf->pcre ? "On" : "Off"); - stats = 1; + pcre = 1; } if (dconf->pcre) diff --git a/libclamav/dconf.h b/libclamav/dconf.h index 3bc4aac99..1099833da 100644 --- a/libclamav/dconf.h +++ b/libclamav/dconf.h @@ -132,6 +132,8 @@ struct cli_dconf { /* PCRE flags */ #define PCRE_CONF_SUPPORT 0x1 +#define PCRE_CONF_OPTIONS 0x2 +#define PCRE_CONF_GLOBAL 0x4 #define BYTECODE_ENGINE_MASK (BYTECODE_INTERPRETER | BYTECODE_JIT_X86 | BYTECODE_JIT_PPC | BYTECODE_JIT_ARM) diff --git a/libclamav/matcher-pcre.c b/libclamav/matcher-pcre.c index a6e827486..19be49e4b 100644 --- a/libclamav/matcher-pcre.c +++ b/libclamav/matcher-pcre.c @@ -210,15 +210,28 @@ int cli_pcre_addpatt(struct cli_matcher *root, const char *trigger, const char * return CL_ENULLARG; } - cli_dbgmsg("cli_pcre_build: Compiling regex: %s\n", pm->pdata.expression); + /* disable global */ + if ((pm->flags & CLI_PCRE_GLOBAL) & !(dconf->pcre & PCRE_CONF_GLOBAL)) { + cli_dbgmsg("cli_pcre_build: disabling global option for regex /%s/\n", pm->pdata.expression); + pm->flags &= ~(CLI_PCRE_GLOBAL); + } /* options override through metadata manipulation */ //pm->pdata.options |= PCRE_NEVER_UTF; /* implemented in 8.33, disables (?UTF*) */ //pm->pdata.options |= PCRE_UCP;/* implemented in 8.20 */ //pm->pdata.options |= PCRE_AUTO_CALLOUT; /* used with CALLOUT(-BACK) function */ - /* parse the regex, no options override *wink* */ - if ((ret = cli_pcre_compile(&(pm->pdata), match_limit, recmatch_limit, 0, 0)) != CL_SUCCESS) { + if (dconf->pcre & PCRE_CONF_OPTIONS) { + /* compile the regex, no options override *wink* */ + cli_dbgmsg("cli_pcre_build: Compiling regex: /%s/\n", pm->pdata.expression); + ret = cli_pcre_compile(&(pm->pdata), match_limit, recmatch_limit, 0, 0); + } + else { + /* compile the regex, options overrided and disabled */ + cli_dbgmsg("cli_pcre_build: Compiling regex: /%s/ (without options)\n", pm->pdata.expression); + ret = cli_pcre_compile(&(pm->pdata), match_limit, recmatch_limit, 0, 1); + } + if (ret != CL_SUCCESS) { cli_errmsg("cli_pcre_build: failed to build pcre regex\n"); pm->flags |= CLI_PCRE_DISABLED; /* disable the pcre */ return ret;