Browse code

properly handle stored files

git-svn: trunk@3546

Tomasz Kojm authored on 2008/01/26 02:23:23
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Jan 25 18:03:22 CET 2008 (tk)
2
+---------------------------------
3
+  * libclamav/cab.c: properly handle stored files
4
+
1 5
 Fri Jan 25 17:35:26 CET 2008 (tk)
2 6
 ---------------------------------
3 7
   * freshclam/manager.c: advertise itself as HTTP/1.0 client
... ...
@@ -561,7 +561,7 @@ static int cab_read(struct cab_file *file, unsigned char *buffer, int bytes)
561 561
     return bytes - todo;
562 562
 }
563 563
 
564
-static int cab_unstore(struct cab_file *file, int bytes, uint8_t wflag)
564
+static int cab_unstore(struct cab_file *file, int bytes)
565 565
 {
566 566
 	int todo;
567 567
 	unsigned char buff[4096];
... ...
@@ -580,7 +580,7 @@ static int cab_unstore(struct cab_file *file, int bytes, uint8_t wflag)
580 580
 	    if(cab_read(file, buff, todo) == -1) {
581 581
 		cli_dbgmsg("cab_unstore: cab_read failed for descriptor %d\n", file->fd);
582 582
 		return CL_EIO;
583
-	    } else if(wflag && cli_writen(file->ofd, buff, todo) == -1) {
583
+	    } else if(cli_writen(file->ofd, buff, todo) == -1) {
584 584
 		cli_dbgmsg("cab_unstore: Can't write to descriptor %d\n", file->ofd);
585 585
 		return CL_EIO;
586 586
 	    }
... ...
@@ -590,7 +590,7 @@ static int cab_unstore(struct cab_file *file, int bytes, uint8_t wflag)
590 590
 	    if(cab_read(file, buff, sizeof(buff)) == -1) {
591 591
 		cli_dbgmsg("cab_unstore: cab_read failed for descriptor %d\n", file->fd);
592 592
 		return CL_EIO;
593
-	    } else if(wflag && cli_writen(file->ofd, buff, sizeof(buff)) == -1) {
593
+	    } else if(cli_writen(file->ofd, buff, sizeof(buff)) == -1) {
594 594
 		cli_dbgmsg("cab_unstore: Can't write to descriptor %d\n", file->ofd);
595 595
 		return CL_EIO;
596 596
 	    }
... ...
@@ -637,7 +637,7 @@ static int cab_unstore(struct cab_file *file, int bytes, uint8_t wflag)
637 637
 	    case 0x0003:						\
638 638
 		file->cab->state->stream = (struct lzx_stream *) lzx_init(file->fd, file->ofd, (int) (file->folder->cmethod >> 8) & 0x1f, 0, 4096, 0, file, &cab_read);									\
639 639
 	}								\
640
-	if(!file->cab->state->stream) {					\
640
+	if((file->folder->cmethod & 0x000f) && !file->cab->state->stream) { \
641 641
 	    free(file->cab->state);					\
642 642
 	    close(file->ofd);						\
643 643
 	    return CL_EMSCAB;						\
... ...
@@ -669,10 +669,9 @@ int cab_extract(struct cab_file *file, const char *name)
669 669
 
670 670
     switch(file->folder->cmethod & 0x000f) {
671 671
 	case 0x0000: /* STORE */
672
-	    if(file->offset > 0)
673
-		cab_unstore(file, file->offset, 0);
674
-
675
-	    ret = cab_unstore(file, file->length, 1);
672
+	    cli_dbgmsg("CAB: Compression method: STORED\n");
673
+	    CAB_CHGFOLDER;
674
+	    ret = cab_unstore(file, file->length);
676 675
 	    break;
677 676
 
678 677
 	case 0x0001: /* MSZIP */