add support for (?i). Now regular expressions that begin with (?i) will be case

insensitive. (bb #1584, #1598).

git-svn: trunk@5067
0.95
Török Edvin 16 years ago
parent ef9c6b65ec
commit 2bc065d467
  1. 8
      ChangeLog
  2. 2
      libclamav/others.h
  3. 9
      libclamav/others_common.c
  4. 4
      libclamav/regex/regcomp.c
  5. 2
      libclamav/regex/regex.h
  6. 31
      unit_tests/check_regex.c

@ -1,3 +1,11 @@
Fri May 15 14:29:19 EEST 2009 (edwin)
-------------------------------------
* libclamav/others.h, libclamav/others_common.c,
libclamav/regex/regcomp.c, libclamav/regex/regex.h,
unit_tests/check_regex.c: add support for (?i). Now regular
expressions that begin with (?i) will be case insensitive. (bb
#1584).
Wed May 6 15:43:27 CEST 2009 (tk)
----------------------------------
* docs/signatures.pdf: describe logical signatures;

@ -34,6 +34,7 @@
#include "clamav.h"
#include "dconf.h"
#include "libclamunrar_iface/unrar_iface.h"
#include "regex/regex.h"
/*
* CL_FLEVEL is the signature f-level specific to the current code and
@ -382,6 +383,7 @@ const char* cli_ctime(const time_t *timep, char *buf, const size_t bufsize);
int cli_checklimits(const char *, cli_ctx *, unsigned long, unsigned long, unsigned long);
int cli_updatelimits(cli_ctx *, unsigned long);
unsigned long cli_getsizelimit(cli_ctx *, unsigned long);
int cli_regcomp(regex_t *preg, const char *pattern, int cflags);
int cli_matchregex(const char *str, const char *regex);
/* symlink behaviour */

@ -820,3 +820,12 @@ int cli_gentempfd(const char *dir, char **name, int *fd)
return CL_SUCCESS;
}
int cli_regcomp(regex_t *preg, const char *pattern, int cflags)
{
if (!strncmp(pattern, "(?i)", 4)) {
pattern += 4;
cflags |= REG_ICASE;
}
return cli_regcomp_real(preg, pattern, cflags);
}

@ -151,10 +151,10 @@ static int never = 0; /* for use in asserts; shuts lint up */
#endif
/*
- cli_regcomp - interface for parser and compilation
- cli_regcomp_real - interface for parser and compilation
*/
int /* 0 success, otherwise REG_something */
cli_regcomp(regex_t *preg, const char *pattern, int cflags)
cli_regcomp_real(regex_t *preg, const char *pattern, int cflags)
{
struct parse pa;
struct re_guts *g;

@ -93,7 +93,7 @@ typedef struct {
#define REG_LARGE 01000 /* force large representation */
#define REG_BACKR 02000 /* force use of backref code */
int cli_regcomp(regex_t *, const char *, int);
int cli_regcomp_real(regex_t *, const char *, int);
size_t cli_regerror(int, const regex_t *, char *, size_t);
int cli_regexec(const regex_t *, const char *, size_t, regmatch_t [], int);
void cli_regfree(regex_t *);

@ -464,6 +464,30 @@ START_TEST (test_url_canon)
fail_unless_fmt(!strcmp(u->path, path), "path incorrect: %s\n", path);
}
END_TEST
static struct regex_test {
const char *regex;
const char *text;
int match;
} rg[] = {
{"\\.exe$", "test.exe", 1},
{"\\.exe$", "test.eXe", 0},
{"(?i)\\.exe$", "test.exe", 1},
{"(?i)\\.exe$", "test.eXe", 1}
};
START_TEST (test_regexes)
{
regex_t reg;
struct regex_test *tst = &rg[_i];
int match;
fail_unless(cli_regcomp(&reg, tst->regex, REG_EXTENDED | REG_NOSUB) == 0, "cli_regcomp");
match = (cli_regexec(&reg, tst->text, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
fail_unless_fmt(match == tst->match, "cli_regexec failed for %s and %s\n", tst->regex, tst->text);
cli_regfree(&reg);
}
END_TEST
#endif
START_TEST(phishing_fake_test)
@ -490,7 +514,7 @@ END_TEST
Suite *test_regex_suite(void)
{
Suite *s = suite_create("regex");
TCase *tc_api, *tc_matching, *tc_phish, *tc_phish2;
TCase *tc_api, *tc_matching, *tc_phish, *tc_phish2, *tc_regex;
tc_api = tcase_create("cli_regex2suffix");
suite_add_tcase(s, tc_api);
@ -525,6 +549,11 @@ Suite *test_regex_suite(void)
tcase_add_loop_test(tc_phish, test_url_canon, 0, sizeof(uc)/sizeof(uc[0]));
#endif
tc_regex = tcase_create("cli_regcomp/execute");
suite_add_tcase(s, tc_regex);
#ifdef CHECK_HAVE_LOOPS
tcase_add_loop_test(tc_regex, test_regexes, 0, sizeof(rg)/sizeof(rg[0]));
#endif
return s;
}

Loading…
Cancel
Save