Browse code

add functionality level support for .pdb/.wdb files

git-svn: trunk@2529

Tomasz Kojm authored on 2006/12/02 09:42:44
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Sat Dec  2 01:41:27 CET 2006 (tk)
2
+---------------------------------
3
+  * libclamav/regex_list.c: add functionality level support for .pdb/.wdb files;
4
+			    patch from Edvin (bb#127)
5
+
1 6
 Sat Dec  2 01:02:45 CET 2006 (tk)
2 7
 ---------------------------------
3 8
   * libclamav: reorganize the NodalCore code and add support for runtime
... ...
@@ -19,6 +19,9 @@
19 19
  *  MA 02110-1301, USA.
20 20
  *
21 21
  *  $Log: regex_list.c,v $
22
+ *  Revision 1.16  2006/12/02 00:42:44  tkojm
23
+ *  add functionality level support for .pdb/.wdb files
24
+ *
22 25
  *  Revision 1.15  2006/11/15 15:26:54  tkojm
23 26
  *  pattern matcher accuracy improvements
24 27
  *
... ...
@@ -524,6 +527,52 @@ static int add_regex_list_element(struct cli_matcher* root,const char* pattern,c
524 524
        return CL_SUCCESS;
525 525
 }
526 526
 
527
+int functionality_level_check(char* line)
528
+{
529
+	char* ptmin;
530
+	char* ptmax;
531
+	size_t j;
532
+
533
+	ptmin = strrchr(line,':');
534
+	if(!ptmin) 
535
+		return CL_SUCCESS;
536
+	
537
+	ptmin++;
538
+
539
+	ptmax = strchr(ptmin,'-');
540
+	if(!ptmax) 
541
+		return CL_SUCCESS;/* there is no functionality level specified, so we're ok */
542
+	else {
543
+		int min, max;
544
+		ptmax++;
545
+		for(j=0;j<ptmax-ptmin-1;j++)
546
+			if(!isdigit(ptmin[j])) 
547
+				return CL_SUCCESS;/* not numbers, not functionality level */
548
+		for(j=0;j<strlen(ptmax);j++)
549
+			if(!isdigit(ptmax[j])) 
550
+				return CL_SUCCESS;/* see above */
551
+		ptmax[-1]='\0';
552
+		min = atoi(ptmin);
553
+		if(strlen(ptmax)==0)
554
+ 			max = INT_MAX; 		
555
+		else
556
+			max = atoi(ptmax);
557
+		if(min<0) min=0;
558
+		if(max<0) max=0;
559
+
560
+		if(min > cl_retflevel()) {
561
+			cli_dbgmsg("regex list line %s not loaded (required f-level: %d)\n",line,min);
562
+			return CL_EMALFDB; 
563
+		}
564
+
565
+		if(max < cl_retflevel()) 
566
+			return CL_EMALFDB;
567
+		ptmin[-1]='\0';
568
+		return CL_SUCCESS;
569
+	}		
570
+}
571
+
572
+
527 573
 /* Load patterns/regexes from file */
528 574
 int load_regex_matcher(struct regex_matcher* matcher,FILE* fd,unsigned int options,int is_whitelist)
529 575
 {
... ...
@@ -570,10 +619,14 @@ int load_regex_matcher(struct regex_matcher* matcher,FILE* fd,unsigned int optio
570 570
 	while(fgets(buffer,FILEBUFF,fd)) {
571 571
 		char* pattern;
572 572
 		char* flags;
573
-		line++;
574 573
 		cli_chomp(buffer);
575 574
 		if(!*buffer)
576 575
 			continue;/* skip empty lines */
576
+
577
+		if(functionality_level_check(buffer)) 
578
+			continue;
579
+
580
+		line++;
577 581
 		pattern = strchr(buffer,':');
578 582
 		if(!pattern) {
579 583
 			cli_errmsg("Malformed regex list line %d\n",line);