Browse code

autoit: more fixes

git-svn: trunk@3347

aCaB authored on 2007/11/01 01:26:37
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Oct 31 16:08:39 CET 2007 (acab)
2
+-----------------------------------
3
+  * libclamav/autoit: misc fixes
4
+
1 5
 Tue Oct 30 22:35:47 CET 2007 (acab)
2 6
 -----------------------------------
3 7
   * libclamav/autoit: misc fixes - big thanks to Edwin
... ...
@@ -25,9 +25,10 @@
25 25
 #include <sys/stat.h>
26 26
 #include <fcntl.h>
27 27
 #include <stdio.h>
28
-/* Gianluigi, you may want to include winsuck here or just make ntohl a macro */
29
-#include <arpa/inet.h>
28
+
29
+#if HAVE_STRING_H
30 30
 #include <string.h>
31
+#endif
31 32
 
32 33
 #ifdef HAVE_UNISTD_H
33 34
 #include <unistd.h>
... ...
@@ -257,7 +258,7 @@ static int ea05(int desc, cli_ctx *ctx, char *tmpd) {
257 257
 	continue;
258 258
       }
259 259
 
260
-      UNP.usize = ntohl(*(uint32_t *)(buf+4));
260
+      UNP.usize = be32_to_host(*(uint32_t *)(buf+4));
261 261
       if(ctx->limits && ctx->limits->maxfilesize && UNP.usize > ctx->limits->maxfilesize) {
262 262
 	cli_dbgmsg("autoit: skipping file due to size limit (%u, max: %lu)\n", UNP.csize, ctx->limits->maxfilesize);
263 263
 	free(buf);
... ...
@@ -484,24 +485,25 @@ static int ea06(int desc, cli_ctx *ctx, char *tmpd) {
484 484
   lseek(desc, 16, SEEK_CUR);   /* for now we just skip the garbage */
485 485
 
486 486
   while(!ctx->limits || !ctx->limits->maxfiles || files < ctx->limits->maxfiles) {
487
-    /* FIXME: count files here */
488 487
     buf = b;
489 488
     if (cli_readn(desc, buf, 8)!=8)
490 489
       return CL_CLEAN;
491
-    /*     LAME_decrypt(buf, 4, 0x18ee); FIXME: waste of time */
490
+    /*     LAME_decrypt(buf, 4, 0x18ee); waste of time */
492 491
     if(cli_readint32((char *)buf) != 0x52ca436b) {
493 492
       cli_dbgmsg("autoit: no FILE magic found, giving up\n");
494 493
       return CL_CLEAN;
495 494
     }
496 495
 
497
-    s = cli_readint32((char *)buf+4) ^ 0xadbc;
498 496
     script = 0;
497
+
498
+    s = cli_readint32((char *)buf+4) ^ 0xadbc;
499
+    if ((int32_t)(s*2)<0)
500
+      return CL_CLEAN; /* the original code wouldn't seek back here */
499 501
     if(s<300) {
500 502
       if (cli_readn(desc, buf, s*2)!=(int)s*2)
501 503
 	return CL_CLEAN;
502 504
       LAME_decrypt(buf,s*2,s+0xb33f);
503
-      buf[s*2]='\0'; buf[s*2+1]='\0';
504
-      u2a(buf,s*2); /* FIXME: GET RID OF THIS */
505
+      u2a(buf,s*2);
505 506
       cli_dbgmsg("autoit: magic string '%s'\n", buf);
506 507
       if (s==19 && !memcmp(">>>AUTOIT SCRIPT<<<", buf, 19))
507 508
 	script = 1;
... ...
@@ -513,12 +515,14 @@ static int ea06(int desc, cli_ctx *ctx, char *tmpd) {
513 513
     if (cli_readn(desc, buf, 4)!=4)
514 514
       return CL_CLEAN;
515 515
     s = cli_readint32((char *)buf) ^ 0xf820;
516
+    if ((int32_t)(s*2)<0)
517
+      return CL_CLEAN; /* the original code wouldn't seek back here */
516 518
     if(cli_debug_flag && s<300) {
517 519
       if (cli_readn(desc, buf, s*2)!=(int)s*2)
518 520
 	return CL_CLEAN;
519 521
       LAME_decrypt(buf,s*2,s+0xf479);
520 522
       buf[s*2]='\0'; buf[s*2+1]='\0';
521
-      u2a(buf,s*2); /* FIXME: GET RID OF THIS */
523
+      u2a(buf,s*2);
522 524
       cli_dbgmsg("autoit: original filename '%s'\n", buf);
523 525
     } else {
524 526
       lseek(desc, s*2, SEEK_CUR);
... ...
@@ -528,6 +532,10 @@ static int ea06(int desc, cli_ctx *ctx, char *tmpd) {
528 528
       return CL_CLEAN;
529 529
     comp = *buf;
530 530
     UNP.csize = cli_readint32((char *)buf+1) ^ 0x87bc;
531
+    if ((int32_t)UNP.csize<0) {
532
+      cli_dbgmsg("autoit: bad file size - giving up\n");
533
+      return CL_CLEAN;
534
+    }
531 535
     cli_dbgmsg("autoit: compressed size: %x\n", UNP.csize);
532 536
     cli_dbgmsg("autoit: advertised uncompressed size %x\n", cli_readint32((char *)buf+5) ^ 0x87bc);
533 537
     cli_dbgmsg("autoit: ref chksum: %x\n", cli_readint32((char *)buf+9) ^ 0xa685);
... ...
@@ -558,7 +566,7 @@ static int ea06(int desc, cli_ctx *ctx, char *tmpd) {
558 558
 	continue;
559 559
       }
560 560
 
561
-      UNP.usize = ntohl(*(uint32_t *)(buf+4));
561
+      UNP.usize = be32_to_host(*(uint32_t *)(buf+4));
562 562
       if(ctx->limits && ctx->limits->maxfilesize && UNP.usize > ctx->limits->maxfilesize) {
563 563
 	free(buf);
564 564
 	continue;