Browse code

only enable signature file type recognition for text files

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@788 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/08/24 09:50:29
Showing 4 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Aug 24 02:30:28 CEST 2004 (tk)
2
+----------------------------------
3
+  * libclamav: only enable signature file type recognition for text files
4
+
1 5
 Mon Aug 23 22:32:02 CEST 2004 (tk)
2 6
 ----------------------------------
3 7
   * include database info in version string (requested by Jason Haar
... ...
@@ -24,6 +24,7 @@
24 24
 #include <stdio.h>
25 25
 #include <string.h>
26 26
 #include <stdlib.h>
27
+#include <ctype.h>
27 28
 
28 29
 #include "clamav.h"
29 30
 #include "filetypes.h"
... ...
@@ -110,7 +111,7 @@ static const struct cli_magic_s cli_magic[] = {
110 110
     {0,  "\060\046\262\165\216\146\317", 7, "WMA/WMV/ASF",	  CL_DATAFILE},
111 111
     {0,  ".RMF" ,			 4, "Real Media File",	  CL_DATAFILE},
112 112
 
113
-    {-1, NULL,				 0, NULL,              CL_UNKNOWN_TYPE}
113
+    {-1, NULL,				 0, NULL,              CL_UNKNOWN_DATA_TYPE}
114 114
 };
115 115
 
116 116
 static const struct cli_smagic_s cli_smagic[] = {
... ...
@@ -136,12 +137,13 @@ static const struct cli_smagic_s cli_smagic[] = {
136 136
     {"3c536372697074", "HTML data", CL_HTMLFILE},	/* <Script */
137 137
     {"3c534352495054", "HTML data", CL_HTMLFILE},	/* <SCRIPT */
138 138
 
139
-    {NULL,  NULL,   CL_UNKNOWN_TYPE}
139
+    {NULL,  NULL,   CL_UNKNOWN_DATA_TYPE}
140 140
 };
141 141
 
142 142
 cli_file_t cli_filetype(const char *buf, size_t buflen)
143 143
 {
144
-	int i;
144
+	int i, ascii = 1;
145
+
145 146
 
146 147
     for(i = 0; cli_magic[i].magic; i++) {
147 148
 	if(buflen >= cli_magic[i].offset+cli_magic[i].length) {
... ...
@@ -152,7 +154,13 @@ cli_file_t cli_filetype(const char *buf, size_t buflen)
152 152
 	}
153 153
     }
154 154
 
155
-    return CL_UNKNOWN_TYPE;
155
+    for(i = 0; i < buflen; i++)
156
+	if(isprint(buf[i])) { /* FIXME: do we need to handle intern. chars? */
157
+	    ascii = 0;
158
+	    break;
159
+	}
160
+
161
+    return ascii ? CL_UNKNOWN_TEXT_TYPE : CL_UNKNOWN_DATA_TYPE;
156 162
 }
157 163
 
158 164
 int cli_addtypesigs(struct cl_node *root)
... ...
@@ -24,7 +24,8 @@
24 24
 #define CL_TYPENO 500
25 25
 
26 26
 typedef enum {
27
-    CL_UNKNOWN_TYPE = CL_TYPENO,
27
+    CL_UNKNOWN_TEXT_TYPE = CL_TYPENO,
28
+    CL_UNKNOWN_DATA_TYPE,
28 29
     CL_DOSEXE,
29 30
     CL_DATAFILE,
30 31
     CL_GZFILE,
... ...
@@ -1125,12 +1125,15 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const
1125 1125
 	    {
1126 1126
 		struct stat s;
1127 1127
 		if(fstat(desc, &s) == 0 && S_ISREG(s.st_mode) && s.st_size < 65536)
1128
-		type = CL_UNKNOWN_TYPE;
1128
+		type = CL_UNKNOWN_DATA_TYPE;
1129 1129
 	    }
1130 1130
 
1131
-	default:
1131
+	case CL_UNKNOWN_DATA_TYPE:
1132 1132
 	    ret = cli_scan_mydoom_log(desc, virname, scanned, root, limits, options, arec, mrec);
1133 1133
 	    break;
1134
+
1135
+	default:
1136
+	    break;
1134 1137
     }
1135 1138
 
1136 1139
     type == CL_MAILFILE ? (*mrec)-- : (*arec)--;
... ...
@@ -1138,7 +1141,7 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const
1138 1138
     if(type != CL_DATAFILE && ret != CL_VIRUS) { /* scan the raw file */
1139 1139
 	    int typerec;
1140 1140
 
1141
-	type == CL_UNKNOWN_TYPE ? (typerec = 1) : (typerec = 0);
1141
+	type == CL_UNKNOWN_TEXT_TYPE ? (typerec = 1) : (typerec = 0);
1142 1142
 	lseek(desc, 0, SEEK_SET);
1143 1143
 
1144 1144
 	if((nret = cli_scandesc(desc, virname, scanned, root, typerec)) == CL_VIRUS) {