Browse code

match_regex: make sure --exclude/include patterns with trailing slashes are handled correctly (bb#820)

git-svn: trunk@3607

Tomasz Kojm authored on 2008/02/11 20:36:11
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon Feb 11 12:21:19 CET 2008 (tk)
2
+---------------------------------
3
+  * clamscan: match_regex: make sure --exclude/include patterns with
4
+	      trailing slashes are handled correctly (bb#820)
5
+
1 6
 Mon Feb 11 11:15:57 CET 2008 (tk)
2 7
 ---------------------------------
3 8
   * shared/misc.c: fix return value of daemonize() under Windows&OS/2 (thx NJH)
... ...
@@ -130,7 +130,10 @@ int match_regex(const char *filename, const char *pattern)
130 130
 {
131 131
 	regex_t reg;
132 132
 	int match, flags;
133
-#if !defined(C_CYGWIN) && !defined(C_OS2)
133
+	char fname[513];
134
+	size_t len;
135
+
136
+#if !defined(C_CYGWIN) && !defined(C_OS2) && !defined(C_WINDOWS)
134 137
 	flags = REG_EXTENDED;
135 138
 #else
136 139
 	flags = REG_EXTENDED | REG_ICASE; /* case insensitive on Windows */
... ...
@@ -139,7 +142,24 @@ int match_regex(const char *filename, const char *pattern)
139 139
 	    logg("!%s: Could not parse regular expression %s.\n", filename, pattern);
140 140
 		return 2;
141 141
 	}
142
-	match = (cli_regexec(&reg, filename, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
142
+
143
+#if !defined(C_CYGWIN) && !defined(C_OS2) && !defined(C_WINDOWS)
144
+	if(pattern[strlen(pattern) - 1] == '/') {
145
+	    snprintf(fname, 511, "%s/", filename);
146
+	    fname[512] = 0;
147
+#else
148
+	if(pattern[strlen(pattern) - 1] == '\\') {
149
+	    strncpy(fname, filename, 510);
150
+	    len = strlen(fname);
151
+	    if(fname[len - 1] != '\\') {
152
+		fname[len] = '\\';
153
+		fname[len + 1] = 0;
154
+	    }
155
+#endif
156
+	} else
157
+	    strncpy(fname, filename, 513);
158
+
159
+	match = (cli_regexec(&reg, fname, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
143 160
 	cli_regfree(&reg);
144 161
 	return match;
145 162
 }