Browse code

properly handle errors from mspack

git-svn: trunk@2737

Tomasz Kojm authored on 2007/02/13 20:01:18
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Feb 13 11:59:32 CET 2007 (tk)
2
+---------------------------------
3
+  * libclamav/cab.c: properly handle errors from mspack
4
+
1 5
 Tue Feb 13 10:02:26 GMT 2007 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/mbox.c:	Fix valgrind error, which could theoretically lead
... ...
@@ -623,6 +623,11 @@ int cab_extract(struct cab_file *file, const char *name)
623 623
 	case 0x0001: /* MSZIP */
624 624
 	    cli_dbgmsg("CAB: Compression method: MSZIP\n");
625 625
 	    file->state->stream = (struct mszip_stream *) mszip_init(file->fd, file->ofd, 4096, 1, file, &cab_read);
626
+	    if(!file->state->stream) {
627
+		free(file->state);
628
+		close(file->ofd);
629
+		return CL_EMSCAB;
630
+	    }
626 631
 	    if(file->offset) {
627 632
 		((struct mszip_stream *) file->state->stream)->wflag = 0;
628 633
 		mszip_decompress(file->state->stream, file->offset);
... ...
@@ -635,6 +640,11 @@ int cab_extract(struct cab_file *file, const char *name)
635 635
 	case 0x0002: /* QUANTUM */
636 636
 	    cli_dbgmsg("CAB: Compression method: QUANTUM\n");
637 637
 	    file->state->stream = (struct qtm_stream *) qtm_init(file->fd, file->ofd, (int) (file->folder->cmethod >> 8) & 0x1f, 4096, file, &cab_read);
638
+	    if(!file->state->stream) {
639
+		free(file->state);
640
+		close(file->ofd);
641
+		return CL_EMSCAB;
642
+	    }
638 643
 	    if(file->offset) {
639 644
 		((struct qtm_stream *) file->state->stream)->wflag = 0;
640 645
 		qtm_decompress(file->state->stream, file->offset);
... ...
@@ -647,6 +657,11 @@ int cab_extract(struct cab_file *file, const char *name)
647 647
 	case 0x0003: /* LZX */
648 648
 	    cli_dbgmsg("CAB: Compression method: LZX\n");
649 649
 	    file->state->stream = (struct lzx_stream *) lzx_init(file->fd, file->ofd, (int) (file->folder->cmethod >> 8) & 0x1f, 0, 4096, 0, file, &cab_read);
650
+	    if(!file->state->stream) {
651
+		free(file->state);
652
+		close(file->ofd);
653
+		return CL_EMSCAB;
654
+	    }
650 655
 	    if(file->offset) {
651 656
 		((struct lzx_stream *) file->state->stream)->wflag = 0;
652 657
 		lzx_decompress(file->state->stream, file->offset);