Browse code

Don't limit '*' to a single 128KB buffer.

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

Tomasz Kojm authored on 2004/03/31 16:15:00
Showing 5 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Mar 31 09:25:25 CEST 2004 (tk)
2
+----------------------------------
3
+  * libclamav: matcher: don't limit '*' to a single 128KB buffer
4
+
1 5
 Tue Mar 30 23:57:33 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/mbox.c:	Better handling of multipart within multipart messages
... ...
@@ -193,21 +193,25 @@ void cl_freetrie(struct cl_node *root)
193 193
     free(root);
194 194
 }
195 195
 
196
-int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root)
196
+int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *pcnt)
197 197
 {
198 198
 	struct cl_node *current;
199 199
 	struct cli_patt *pt;
200
-	int position, *partcnt;
200
+	int position, *partcnt, extpartcnt = 0;
201 201
         unsigned int i;
202 202
 
203 203
     current = (struct cl_node *) root;
204 204
 
205
-    if ((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
206
-	cli_dbgmsg("cl_scanbuff(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
207
-	return CL_EMEM;
205
+    if(pcnt) {
206
+	partcnt = pcnt;
207
+	extpartcnt = 1;
208
+    } else {
209
+	if((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
210
+	    cli_dbgmsg("cl_scanbuff(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
211
+	    return CL_EMEM;
212
+	}
208 213
     }
209 214
 
210
-
211 215
     for(i = 0; i < length; i++)  {
212 216
 	current = current->trans[(unsigned char) buffer[i] & 0xff];
213 217
 
... ...
@@ -222,14 +226,16 @@ int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, c
222 222
 			    if(++partcnt[pt->sigid] == pt->parts) { /* last */
223 223
 				if(virname)
224 224
 				    *virname = pt->virname;
225
-				free(partcnt);
225
+				if(!extpartcnt)
226
+				    free(partcnt);
226 227
 				return CL_VIRUS;
227 228
 			    }
228 229
 			}
229 230
 		    } else { /* old type signature */
230 231
 			if(virname)
231 232
 			    *virname = pt->virname;
232
-			free(partcnt);
233
+			if(!extpartcnt)
234
+			    free(partcnt);
233 235
 			return CL_VIRUS;
234 236
 		    }
235 237
 		}
... ...
@@ -241,10 +247,17 @@ int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, c
241 241
 	}
242 242
     }
243 243
 
244
-    free(partcnt);
244
+    if(!extpartcnt)
245
+	free(partcnt);
245 246
     return CL_CLEAN;
246 247
 }
247 248
 
249
+int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root)
250
+
251
+{
252
+    return cli_scanbuff(buffer, length, virname, root, NULL);
253
+}
254
+
248 255
 int cli_findpos(const char *buffer, int offset, int length, const struct cli_patt *pattern)
249 256
 {
250 257
 	int bufferpos = offset + CL_MIN_LENGTH;
... ...
@@ -31,5 +31,6 @@ struct nodelist *cli_bfsadd(struct nodelist *bfs, struct cl_node *n);
31 31
 void cli_failtrans(struct cl_node *root);
32 32
 void cli_fasttrie(struct cl_node *n, struct cl_node *root);
33 33
 int cli_findpos(const char *buffer, int offset, int length, const struct cli_patt *pattern);
34
+int cli_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cl_node *root, int *pcnt);
34 35
 
35 36
 #endif
... ...
@@ -225,6 +225,7 @@ void *cli_malloc(size_t size)
225 225
     if(!alloc) {
226 226
 	cli_errmsg("cli_malloc(): Can't allocate memory (%d bytes).\n", size);
227 227
 	perror("malloc_problem");
228
+	/* _exit(1); */
228 229
 	return NULL;
229 230
     } else return alloc;
230 231
 }
... ...
@@ -238,6 +239,7 @@ void *cli_calloc(size_t nmemb, size_t size)
238 238
     if(!alloc) {
239 239
 	cli_errmsg("cli_calloc(): Can't allocate memory (%d bytes).\n", nmemb * size);
240 240
 	perror("calloc_problem");
241
+	/* _exit(1); */
241 242
 	return NULL;
242 243
     } else return alloc;
243 244
 }
... ...
@@ -113,7 +113,7 @@ static int cli_scandesc(int desc, const char **virname, long int *scanned, const
113 113
 cl_node *root)
114 114
 {
115 115
  	char *buffer, *buff, *endbl, *pt;
116
-	int bytes, buffsize, length, ret;
116
+	int bytes, buffsize, length, ret, *partcnt;
117 117
 
118 118
     /* prepare the buffer */
119 119
     buffsize = root->maxpatlen + SCANBUFF;
... ...
@@ -122,6 +122,12 @@ cl_node *root)
122 122
 	return CL_EMEM;
123 123
     }
124 124
 
125
+    if((partcnt = (int *) cli_calloc(root->partsigs + 1, sizeof(int))) == NULL) {
126
+	cli_dbgmsg("cl_scandesc(): unable to calloc(%d, %d)\n", root->partsigs + 1, sizeof(int));
127
+	free(buffer);
128
+	return CL_EMEM;
129
+    }
130
+
125 131
     buff = buffer;
126 132
     buff += root->maxpatlen; /* pointer to read data block */
127 133
     endbl = buff + SCANBUFF - root->maxpatlen; /* pointer to the last block
... ...
@@ -138,8 +144,9 @@ cl_node *root)
138 138
 	if(bytes < SCANBUFF)
139 139
 	    length -= SCANBUFF - bytes;
140 140
 
141
-	if((ret = cl_scanbuff(pt, length, virname, root)) != CL_CLEAN) {
141
+	if((ret = cli_scanbuff(pt, length, virname, root, partcnt)) != CL_CLEAN) {
142 142
 	    free(buffer);
143
+	    free(partcnt);
143 144
 	    return ret;
144 145
 	}
145 146
 
... ...
@@ -152,6 +159,7 @@ cl_node *root)
152 152
     }
153 153
 
154 154
     free(buffer);
155
+    free(partcnt);
155 156
     return CL_CLEAN;
156 157
 }
157 158