Browse code

libclamav: use a regex for the filename field in .zmd/.rmd (bb#193)

git-svn: trunk@3973

Tomasz Kojm authored on 2008/07/19 02:57:27
Showing 5 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Jul 18 19:33:41 CEST 2008 (tk)
2
+----------------------------------
3
+  * libclamav: use a regex for the filename field in .zmd/.rmd (bb#193)
4
+
1 5
 Fri Jul 18 18:25:32 CEST 2008 (tk)
2 6
 ----------------------------------
3 7
   * freshclam/freshclam.c: improve some msgs (bb#1066)
... ...
@@ -77,6 +77,7 @@ static pthread_mutex_t cli_ctime_mutex = PTHREAD_MUTEX_INITIALIZER;
77 77
 #include "others.h"
78 78
 #include "md5.h"
79 79
 #include "cltypes.h"
80
+#include "regex/regex.h"
80 81
 
81 82
 #ifndef	O_BINARY
82 83
 #define	O_BINARY	0
... ...
@@ -953,3 +954,16 @@ const char* cli_ctime(const time_t *timep, char *buf, const size_t bufsize)
953 953
 	return ret;
954 954
 }
955 955
 
956
+int cli_matchregex(const char *str, const char *regex)
957
+{
958
+	regex_t reg;
959
+	int match;
960
+
961
+    if(cli_regcomp(&reg, regex, REG_EXTENDED) == 0) {
962
+	match = (cli_regexec(&reg, str, 0, NULL, 0) == REG_NOMATCH) ? 0 : 1;
963
+	cli_regfree(&reg);
964
+	return match;
965
+    }
966
+
967
+    return 0;
968
+}
... ...
@@ -275,4 +275,5 @@ const char* cli_ctime(const time_t *timep, char *buf, const size_t bufsize);
275 275
 int cli_checklimits(const char *, cli_ctx *, unsigned long, unsigned long, unsigned long);
276 276
 int cli_updatelimits(cli_ctx *, unsigned long);
277 277
 unsigned long cli_getsizelimit(cli_ctx *, unsigned long);
278
+int cli_matchregex(const char *str, const char *regex);
278 279
 #endif
... ...
@@ -239,9 +239,7 @@ static int cli_unrar_scanmetadata(int desc, unrar_metadata_t *metadata, cli_ctx
239 239
 	if(mdata->maxdepth && ctx->recursion > mdata->maxdepth)
240 240
 	    continue;
241 241
 
242
-	/* TODO add support for regex */
243
-	/*if(mdata->filename && !strstr(zdirent.d_name, mdata->filename))*/
244
-	if(mdata->filename && strcmp((char *) metadata->filename, mdata->filename))
242
+	if(mdata->filename && !cli_matchregex(metadata->filename, mdata->filename))
245 243
 	    continue;
246 244
 
247 245
 	break; /* matched */
... ...
@@ -347,7 +347,7 @@ static unsigned int lhdr(uint8_t *zip, uint32_t zsize, unsigned int *fu, unsigne
347 347
 	 (meta->method>0 && meta->method != LH_method) ||
348 348
 	 (meta->fileno   && meta->fileno != fc ) ||
349 349
 	 (meta->maxdepth && ctx->recursion > meta->maxdepth) ||
350
-	 (meta->filename && strcmp(name, meta->filename)) /* TODO: use a regex */
350
+	 (meta->filename && !cli_matchregex(name, meta->filename))
351 351
 	 )
352 352
 	) meta = meta->next;
353 353
   if(meta) {