Browse code

fix possible seek loop

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

Trog authored on 2005/03/12 04:18:01
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Mar 11 19:15:47 GMT 2005 (trog)
2
+-----------------------------------
3
+  * libclamav/vba_extract.c: fix possible seek loop
4
+
1 5
 Thu Mar 10 13:32:38 GMT 2005 (trog)
2 6
 -----------------------------------
3 7
   * libclamav/special.c: Check Photoshop thumbnail images embedded in JPEG files.
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  *  Extract VBA source code for component MS Office Documents
3 3
  *
4
- *  Copyright (C) 2004 trog@uncon.org
4
+ *  Copyright (C) 2004-2005 trog@uncon.org
5 5
  *
6 6
  *  This code is based on the OpenOffice and libgsf sources.
7 7
  *                  
... ...
@@ -810,6 +810,7 @@ static char *ppt_stream_iter(int fd)
810 810
 	atom_header_t atom_header;
811 811
 	uint32_t ole_id;
812 812
 	char *out_dir;
813
+	off_t offset;
813 814
 	
814 815
 	/* Create a directory to store the extracted OLE2 objects */
815 816
 	out_dir = cli_gentemp(NULL);
... ...
@@ -826,7 +827,7 @@ static char *ppt_stream_iter(int fd)
826 826
 		}
827 827
 		ppt_print_atom_header(&atom_header);
828 828
 
829
-		if (atom_header.length <= 0) {
829
+		if (atom_header.length == 0) {
830 830
 			cli_rmdirs(out_dir);
831 831
 			free(out_dir);
832 832
 			return NULL;
... ...
@@ -850,7 +851,13 @@ static char *ppt_stream_iter(int fd)
850 850
 			}
851 851
 
852 852
 		} else {
853
-			if (lseek(fd, atom_header.length, SEEK_CUR) == -1 ) {
853
+			offset = lseek(fd, 0, SEEK_CUR);
854
+			/* Check we don't wrap */
855
+			if ((offset + atom_header.length) < offset) {
856
+				break;
857
+			}
858
+			offset += atom_header.length;
859
+			if (lseek(fd, offset, SEEK_SET) != offset ) {
854 860
 				break;
855 861
 			}
856 862
 		}