pcre: fixed an issue where expression was not copied

pcre: added search offset override to cli_pcre_match
remotes/push_mirror/swebb/clamyara^2
Kevin Lin 11 years ago
parent 9bc7c13882
commit 3f8f8721a1
  1. 6
      libclamav/matcher-pcre.c
  2. 10
      libclamav/regex_pcre.c
  3. 4
      libclamav/regex_pcre.h

@ -48,7 +48,7 @@ int cli_pcre_addpatt(struct cli_matcher *root, const char *pattern, const uint32
return CL_ENULLARG; return CL_ENULLARG;
} }
/* TODO: regex checking */ /* TODO: regex checking (string length limitations) */
//cli_pcre_free_single(pd); //cli_pcre_free_single(pd);
/* allocating entries */ /* allocating entries */
@ -58,6 +58,8 @@ int cli_pcre_addpatt(struct cli_matcher *root, const char *pattern, const uint32
return CL_EMEM; return CL_EMEM;
} }
pd->expression = strdup(pattern);
refe = (struct cli_pcre_refentry *)cli_calloc(1, sizeof(struct cli_pcre_refentry)); refe = (struct cli_pcre_refentry *)cli_calloc(1, sizeof(struct cli_pcre_refentry));
if (!refe) { if (!refe) {
cli_errmsg("cli_pcre_addpatt: failed to allocate space\n"); cli_errmsg("cli_pcre_addpatt: failed to allocate space\n");
@ -131,7 +133,7 @@ int cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const struct
cli_dbgmsg("cli_pcre_scanbuf: running regex /%s/\n", pd->expression); cli_dbgmsg("cli_pcre_scanbuf: running regex /%s/\n", pd->expression);
rc = cli_pcre_match(pd, buffer, length, ovector, OVECCOUNT); rc = cli_pcre_match(pd, buffer, length, CLI_PCREMATCH_NOOVERRIDE, ovector, OVECCOUNT);
cli_dbgmsg("cli_pcre_scanbuf: running regex /%s/ returns %d\n", pd->expression, rc); cli_dbgmsg("cli_pcre_scanbuf: running regex /%s/ returns %d\n", pd->expression, rc);
if (rc > 0) { /* matched at least once */ if (rc > 0) { /* matched at least once */

@ -106,16 +106,20 @@ int cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, l
} }
/* TODO: fix this function */ /* TODO: fix this function */
int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int *ovector, size_t ovlen) int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int override_offset, int *ovector, size_t ovlen)
{ {
int rc; int rc, startoffset;
if (ovlen % 3) { if (ovlen % 3) {
cli_dbgmsg("cli_pcre_match: ovector length is not a multiple of 3\n"); cli_dbgmsg("cli_pcre_match: ovector length is not a multiple of 3\n");
return CL_EARG; return CL_EARG;
} }
rc = pcre_exec(pd->re, pd->ex, buffer, buflen, pd->search_offset, pd->options, ovector, ovlen); startoffset = pd->search_offset;
if (override_offset >= 0)
startoffset = override_offset;
rc = pcre_exec(pd->re, pd->ex, buffer, buflen, startoffset, pd->options, ovector, ovlen);
return rc; return rc;
} }

@ -35,6 +35,8 @@
#include "cltypes.h" #include "cltypes.h"
#include "mpool.h" #include "mpool.h"
/* used for setting no override */
#define CLI_PCREMATCH_NOOVERRIDE -1
/* must be multiple of 3 */ /* must be multiple of 3 */
#define OVECCOUNT 300 #define OVECCOUNT 300
@ -48,7 +50,7 @@ struct cli_pcre_data {
int cli_pcre_parse(struct cli_pcre_data *pd, const char *pattern); int cli_pcre_parse(struct cli_pcre_data *pd, const char *pattern);
int cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options); int cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options);
int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int *ovector, size_t ovlen); int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, uint32_t buflen, int override_offset, int *ovector, size_t ovlen);
void cli_pcre_free_single(struct cli_pcre_data *pd); void cli_pcre_free_single(struct cli_pcre_data *pd);
#endif /* HAVE_PCRE */ #endif /* HAVE_PCRE */
#endif /*_REGEX_PCRE_H_*/ #endif /*_REGEX_PCRE_H_*/

Loading…
Cancel
Save