Browse code

update limits

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

aCaB authored on 2008/02/08 10:57:50
Showing 6 changed files
... ...
@@ -113,5 +113,8 @@ typedef struct chm_metadata_tag {
113 113
 } chm_metadata_t;
114 114
 
115 115
 int chm_unpack(int fd, const char *dirname);
116
-
116
+int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata);
117
+void cli_chm_close(chm_metadata_t *metadata);
118
+int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata);
119
+int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata);
117 120
 #endif
... ...
@@ -475,7 +475,7 @@ static void ole2_walk_property_tree(int fd, ole2_header_t *hdr, const char *dir,
475 475
 	if ((prop_index < 0) || (prop_index > hdr->max_block_no) || (rec_level > 100) || (*file_count > 100000)) {
476 476
 		return;
477 477
 	}
478
-
478
+	/* FIXMELIMITS */
479 479
 	if (limits && limits->maxfiles && (*file_count > limits->maxfiles)) {
480 480
 		cli_dbgmsg("OLE2: File limit reached (max: %d)\n", limits->maxfiles);
481 481
 		return;
... ...
@@ -196,16 +196,6 @@ const char *cl_strerror(int clerror)
196 196
     }
197 197
 }
198 198
 
199
-unsigned long cli_getsizelimit(cli_ctx *ctx, unsigned long needed) {
200
-    if(!ctx || ! ctx->limits)
201
-	return needed;
202
-    if(needed > ctx->limits->maxfilesize)
203
-	needed = ctx->limits->maxfilesize;
204
-    if(needed > ctx->limits->maxscansize-ctx->scansize)
205
-	needed = ctx->limits->maxscansize-ctx->scansize;
206
-    return needed;
207
-}
208
-
209 199
 int cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, unsigned long need2, unsigned long need3) {
210 200
     int ret = CL_SUCCESS;
211 201
     unsigned long needed;
... ...
@@ -221,7 +211,7 @@ int cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, unsigned
221 221
         /* if the remaining scansize is too small... */
222 222
         if(ctx->limits->maxscansize-ctx->scansize<needed) {
223 223
 	    /* ... we tell the caller to skip this file */
224
-	    cli_dbgmsg("%s: scansize exceeded (initial: %u, remaining: %u, needed: %u)\n", who, ctx->limits->maxscansize, ctx->scansize, needed);
224
+	    cli_dbgmsg("%s: scansize exceeded (initial: %lu, remaining: %lu, needed: %lu)\n", who, ctx->limits->maxscansize, ctx->scansize, needed);
225 225
 	    ret = CL_EMAXSIZE;
226 226
 	}
227 227
     }
... ...
@@ -229,7 +219,7 @@ int cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, unsigned
229 229
     /* if we have per-file size limits, and we are overlimit... */
230 230
     if(needed && ctx->limits->maxfilesize && ctx->limits->maxfilesize<needed) {
231 231
 	/* ... we tell the caller to skip this file */
232
-        cli_dbgmsg("%s: filesize exceeded (allowed: %u, needed: %u)\n", who, ctx->limits->maxfilesize, needed);
232
+        cli_dbgmsg("%s: filesize exceeded (allowed: %lu, needed: %lu)\n", who, ctx->limits->maxfilesize, needed);
233 233
 	ret = CL_EMAXSIZE;
234 234
     }
235 235
 
... ...
@@ -241,17 +231,14 @@ int cli_checklimits(const char *who, cli_ctx *ctx, unsigned long need1, unsigned
241 241
 }
242 242
 
243 243
 int cli_updatelimits(cli_ctx *ctx, unsigned long needed) {
244
-    /* FIXMELIMITS:
245
-     *  we enter here via magicscan only
246
-     *  magiscan callers should check for !CL_CLEAN instead of CL_VIRUS
247
-     */
244
+    int ret=cli_checklimits("cli_updatelimits", ctx, needed, 0, 0);
248 245
 
246
+    if (ret != CL_CLEAN) return ret;
249 247
     ctx->scannedfiles++;
250 248
     ctx->scansize+=needed;
251 249
     if(ctx->scansize > ctx->limits->maxscansize)
252 250
         ctx->scansize = ctx->limits->maxscansize;
253
-
254
-    return cli_checklimits("updatelimits", ctx, needed, 0, 0);
251
+    return CL_CLEAN;
255 252
 }
256 253
 
257 254
 unsigned char *cli_md5digest(int desc)
... ...
@@ -82,10 +82,9 @@
82 82
 #define PESALIGN(o,a) (((a))?(((o)/(a)+((o)%(a)!=0))*(a)):(o))
83 83
 
84 84
 #define CLI_UNPSIZELIMITS(NAME,CHK) \
85
-if(ctx->limits && ctx->limits->maxfilesize && (CHK) > ctx->limits->maxfilesize) { \
86
-  cli_dbgmsg(NAME": Sizes exceeded (%lu > %lu)\n", (unsigned long)(CHK), (unsigned long)ctx->limits->maxfilesize); \
87
-    free(exe_sections); \
88
-    return CL_CLEAN;	\
85
+if(cli_checklimits(NAME, ctx, (CHK), 0, 0)!=CL_CLEAN) {	\
86
+    free(exe_sections);					\
87
+    return CL_CLEAN;					\
89 88
 }
90 89
 
91 90
 #define CLI_UNPTEMP(NAME,FREEME) \
... ...
@@ -286,7 +286,6 @@ static int cli_scanarj(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
286 286
 	int ret = CL_CLEAN, rc;
287 287
 	arj_metadata_t metadata;
288 288
 	char *dir;
289
-	unsigned int file_count = 1;
290 289
 
291 290
     cli_dbgmsg("in cli_scanarj()\n");
292 291
 
... ...
@@ -1094,7 +1093,6 @@ static int cli_scanmschm(int desc, cli_ctx *ctx)
1094 1094
 	int ret = CL_CLEAN, rc;
1095 1095
 	chm_metadata_t metadata;
1096 1096
 	char *dir;
1097
-	unsigned int file_count = 1;
1098 1097
 
1099 1098
     cli_dbgmsg("in cli_scanmschm()\n");
1100 1099
 
... ...
@@ -1631,6 +1629,9 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
1631 1631
 	return ret;
1632 1632
     }
1633 1633
 
1634
+    if(cli_updatelimits(ctx, sb.st_size)!=CL_CLEAN)
1635
+        return CL_CLEAN;
1636
+
1634 1637
     if((SCAN_MAIL || SCAN_ARCHIVE) && ctx->limits && ctx->limits->maxreclevel && ctx->recursion > ctx->limits->maxreclevel) {
1635 1638
         cli_dbgmsg("Archive recursion limit exceeded (level = %u).\n", ctx->recursion);
1636 1639
 	return CL_CLEAN;
... ...
@@ -372,6 +372,7 @@ int unspin(char *src, int ssize, struct cli_exe_section *sections, int sectcnt,
372 372
   bitmap = cli_readint32(ep+0x3061);
373 373
   bitman = bitmap;
374 374
 
375
+  /* FIXMELIMITS */
375 376
   if(ctx->limits && ctx->limits->maxfilesize) {
376 377
     unsigned long int filesize = 0;
377 378