[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-167-g4319a8f

edwin edwin at 77e5149b-7576-45b1-b177-96237e5ba77b
Fri Jun 12 19:12:11 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 8b97553a42771449115ccc07e1bda04b9b6aaff1
Author: edwin <edwin at 77e5149b-7576-45b1-b177-96237e5ba77b>
Date:   Fri May 15 11:53:22 2009 +0000

    add support for (?i). Now regular expressions that begin with (?i) will be case
    insensitive. (bb #1584, #1598).
    
    git-svn-id: http://svn.clamav.net/svn/clamav-devel/trunk@5067 77e5149b-7576-45b1-b177-96237e5ba77b

diff --git a/ChangeLog b/ChangeLog
index c24d8cb..ee02056 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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;
diff --git a/libclamav/others.h b/libclamav/others.h
index 7e636a7..817f8f0 100644
--- a/libclamav/others.h
+++ b/libclamav/others.h
@@ -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 */
diff --git a/libclamav/others_common.c b/libclamav/others_common.c
index 422836c..01c6fbe 100644
--- a/libclamav/others_common.c
+++ b/libclamav/others_common.c
@@ -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);
+}
diff --git a/libclamav/regex/regcomp.c b/libclamav/regex/regcomp.c
index 9fcdb18..f711603 100644
--- a/libclamav/regex/regcomp.c
+++ b/libclamav/regex/regcomp.c
@@ -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;
diff --git a/libclamav/regex/regex.h b/libclamav/regex/regex.h
index 5e37eb1..fef74ec 100644
--- a/libclamav/regex/regex.h
+++ b/libclamav/regex/regex.h
@@ -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 *);
diff --git a/unit_tests/check_regex.c b/unit_tests/check_regex.c
index b67c1f1..ce18af0 100644
--- a/unit_tests/check_regex.c
+++ b/unit_tests/check_regex.c
@@ -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;
 }
 

-- 
Debian repository for ClamAV



More information about the Pkg-clamav-commits mailing list