Browse code

Tidy up and removed some unused code

git-svn: trunk@3348

Nigel Horne authored on 2007/11/01 03:36:02
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Oct 31 17:45:45 GMT 2007 (njh)
2
+----------------------------------
3
+  * libclamav/vba_extract.c:	Tidy up and removed some unused code
4
+
1 5
 Wed Oct 31 16:08:39 CET 2007 (acab)
2 6
 -----------------------------------
3 7
   * libclamav/autoit: misc fixes
... ...
@@ -201,12 +201,12 @@ static void vba56_test_middle(int fd)
201 201
 
202 202
 static int vba_read_project_strings(int fd, int is_mac)
203 203
 {
204
-	uint16_t length;
205
-	unsigned char *buff;
206
-	char *name;
207
-	uint32_t offset;
208
-
209 204
 	for (;;) {
205
+		uint32_t offset;
206
+		uint16_t length;
207
+		unsigned char *buff;
208
+		char *name;
209
+
210 210
 		if (cli_readn(fd, &length, 2) != 2) {
211 211
 			return FALSE;
212 212
 		}
... ...
@@ -243,6 +243,8 @@ static int vba_read_project_strings(int fd, int is_mac)
243 243
 		/* TODO: Need to check if types H(same as G) and D(same as C) exist */
244 244
 		if (name && (!strncmp ("*\\G", name, 3) || !strncmp ("*\\H", name, 3)
245 245
 				|| !strncmp("*\\C", name, 3) || !strncmp("*\\D", name, 3))) {
246
+			char namebuff[10];
247
+
246 248
 			if (cli_readn(fd, &length, 2) != 2) {
247 249
 				return FALSE;
248 250
 			}
... ...
@@ -252,20 +254,12 @@ static int vba_read_project_strings(int fd, int is_mac)
252 252
 				free(name);
253 253
 				continue;
254 254
 			}
255
-			buff = (unsigned char *) cli_malloc(10);
256
-			if (!buff) {
255
+			if (cli_readn(fd, namebuff, sizeof(namebuff)) != sizeof(namebuff)) {
256
+				cli_errmsg("failed to read namebuff\n");
257 257
 				free(name);
258 258
 				close(fd);
259 259
 				return FALSE;
260 260
 			}
261
-			if (cli_readn(fd, buff, 10) != 10) {
262
-				cli_errmsg("failed to read blob\n");
263
-				free(buff);
264
-				free(name);
265
-				close(fd);
266
-				return FALSE;
267
-			}
268
-			free(buff);
269 261
 		} else {
270 262
 			/* Unknown type - probably ran out of strings - rewind */
271 263
 			lseek(fd, -(length+2), SEEK_CUR);
... ...
@@ -292,25 +286,19 @@ vba_project_t *vba56_dir_read(const char *dir)
292 292
 	uint32_t offset;
293 293
 	int i, fd, is_mac;
294 294
 	vba_project_t *vba_project;
295
-	char *fullname;
296 295
 	struct vba56_header v56h;
296
+	char fullname[NAME_MAX + 1];
297 297
 
298 298
 	cli_dbgmsg("in vba56_dir_read()\n");
299 299
 
300
-	fullname = (char *) cli_malloc(strlen(dir) + 14);
301
-	if (!fullname) {
302
-		return NULL;
303
-	}
304
-	sprintf(fullname, "%s/_VBA_PROJECT", dir);
300
+	snprintf(fullname, sizeof(fullname) - 1, "%s/_VBA_PROJECT", dir);
305 301
         fd = open(fullname, O_RDONLY|O_BINARY);
306 302
 
307 303
         if (fd == -1) {
308 304
                 cli_dbgmsg("Can't open %s\n", fullname);
309
-		free(fullname);
310 305
 		/* vba56_old_dir_read(dir); */
311 306
                 return NULL;
312 307
         }
313
-	free(fullname);
314 308
 
315 309
 	if(cli_readn(fd, &v56h, sizeof(struct vba56_header)) != sizeof(struct vba56_header)) {
316 310
 		close(fd);
... ...
@@ -911,7 +899,7 @@ char *ppt_vba_read(const char *dir)
911 911
 	fd = open(fullname, O_RDONLY|O_BINARY);
912 912
 	free(fullname);
913 913
 	if (fd == -1) {
914
-		cli_dbgmsg("Open  PowerPoint Document failed\n");
914
+		cli_dbgmsg("Open PowerPoint Document failed\n");
915 915
 		return NULL;
916 916
 	}
917 917
 
... ...
@@ -926,12 +914,9 @@ char *ppt_vba_read(const char *dir)
926 926
 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
927 927
 
928 928
 typedef struct mso_fib_tag {
929
-	uint16_t magic;
930
-	uint16_t version;
931
-	uint16_t product;
932
-	uint16_t lid;
933
-	uint16_t next;
934
-	uint16_t status;
929
+	char ununsed[sizeof(uint16_t) + sizeof(uint16_t) +
930
+		sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) +
931
+		sizeof(uint16_t)];
935 932
 	/* block of 268 bytes - ignore */
936 933
 	uint32_t macro_offset;
937 934
 	uint32_t macro_len;
... ...
@@ -1007,41 +992,12 @@ static	void	wm_free_macro_info(macro_info_t *macro_info);
1007 1007
 
1008 1008
 static void wm_print_fib(mso_fib_t *fib)
1009 1009
 {
1010
-	cli_dbgmsg("magic: 0x%.4x\n", fib->magic);
1011
-	cli_dbgmsg("version: 0x%.4x\n", fib->version);
1012
-	cli_dbgmsg("product: 0x%.4x\n", fib->product);
1013
-	cli_dbgmsg("lid: 0x%.4x\n", fib->lid);
1014 1010
 	cli_dbgmsg("macro offset: 0x%.4x\n", fib->macro_offset);
1015 1011
 	cli_dbgmsg("macro len: 0x%.4x\n\n", fib->macro_len);
1016 1012
 }
1017 1013
 
1018 1014
 static int wm_read_fib(int fd, mso_fib_t *fib)
1019 1015
 {
1020
-	if (cli_readn(fd, &fib->magic, 2) != 2) {
1021
-		cli_dbgmsg("read wm_fib failed\n");
1022
-		return FALSE;
1023
-	}
1024
-	if (cli_readn(fd, &fib->version, 2) != 2) {
1025
-		cli_dbgmsg("read wm_fib failed\n");
1026
-		return FALSE;
1027
-	}
1028
-	if (cli_readn(fd, &fib->product, 2) != 2) {
1029
-		cli_dbgmsg("read wm_fib failed\n");
1030
-		return FALSE;
1031
-	}
1032
-	if (cli_readn(fd, &fib->lid, 2) != 2) {
1033
-		cli_dbgmsg("read wm_fib failed\n");
1034
-		return FALSE;
1035
-	}
1036
-	if (cli_readn(fd, &fib->next, 2) != 2) {
1037
-		cli_dbgmsg("read wm_fib failed\n");
1038
-		return FALSE;
1039
-	}
1040
-	if (cli_readn(fd, &fib->status, 2) != 2) {
1041
-		cli_dbgmsg("read wm_fib failed\n");
1042
-		return FALSE;
1043
-	}
1044
-
1045 1016
 	/* don't need the information is this block, so seek forward */
1046 1017
 	if (lseek(fd, 0x118, SEEK_SET) != 0x118) {
1047 1018
 		cli_dbgmsg("lseek wm_fib failed\n");
... ...
@@ -1056,12 +1012,6 @@ static int wm_read_fib(int fd, mso_fib_t *fib)
1056 1056
 		cli_dbgmsg("read wm_fib failed\n");
1057 1057
 		return FALSE;
1058 1058
 	}
1059
-	fib->magic = vba_endian_convert_16(fib->magic, FALSE);
1060
-	fib->version = vba_endian_convert_16(fib->version, FALSE);
1061
-	fib->product = vba_endian_convert_16(fib->product, FALSE);
1062
-	fib->lid = vba_endian_convert_16(fib->lid, FALSE);
1063
-	fib->next = vba_endian_convert_16(fib->next, FALSE);
1064
-	fib->status = vba_endian_convert_16(fib->status, FALSE);
1065 1059
 	fib->macro_offset = vba_endian_convert_32(fib->macro_offset, FALSE);
1066 1060
 	fib->macro_len = vba_endian_convert_32(fib->macro_len, FALSE);
1067 1061
 
... ...
@@ -1472,7 +1422,6 @@ vba_project_t *wm_dir_read(const char *dir)
1472 1472
 	off_t end_offset;
1473 1473
 	unsigned char start_id, info_id;
1474 1474
 	macro_info_t *macro_info=NULL;
1475
-	menu_info_t *menu_info=NULL;
1476 1475
 	macro_extnames_t *macro_extnames=NULL;
1477 1476
 	macro_intnames_t *macro_intnames=NULL;
1478 1477
 	vba_project_t *vba_project=NULL;
... ...
@@ -1512,6 +1461,8 @@ vba_project_t *wm_dir_read(const char *dir)
1512 1512
 	cli_dbgmsg("start_id: %d\n", start_id);
1513 1513
 
1514 1514
 	while ((lseek(fd, 0, SEEK_CUR) < end_offset) && !done) {
1515
+		menu_info_t *menu_info;
1516
+
1515 1517
 		if (cli_readn(fd, &info_id, 1) != 1) {
1516 1518
 			cli_dbgmsg("read macro_info failed\n");
1517 1519
 			close(fd);
... ...
@@ -1531,9 +1482,10 @@ vba_project_t *wm_dir_read(const char *dir)
1531 1531
 				break;
1532 1532
 			case 0x05:
1533 1533
 				menu_info = wm_read_menu_info(fd);
1534
-				if (menu_info == NULL) {
1534
+				if(menu_info)
1535
+					wm_free_menu_info(menu_info);
1536
+				else
1535 1537
 					done = TRUE;
1536
-				}
1537 1538
 				break;
1538 1539
 			case 0x10:
1539 1540
 				macro_extnames = wm_read_macro_extnames(fd);
... ...
@@ -1604,14 +1556,14 @@ vba_project_t *wm_dir_read(const char *dir)
1604 1604
 			free(vba_project->dir);
1605 1605
 			free(vba_project);
1606 1606
 			vba_project = NULL;
1607
-			goto abort;
1608
-		}
1609
-		vba_project->count = macro_info->count;
1610
-		for (i=0 ; i < macro_info->count ; i++) {
1611
-			vba_project->name[i] = cli_strdup("WordDocument");
1612
-			vba_project->offset[i] = macro_info->macro_entry[i].offset;
1613
-			vba_project->length[i] = macro_info->macro_entry[i].len;
1614
-			vba_project->key[i] = macro_info->macro_entry[i].key;
1607
+		} else {
1608
+			vba_project->count = macro_info->count;
1609
+			for(i = 0; i < macro_info->count; i++) {
1610
+				vba_project->name[i] = cli_strdup("WordDocument");
1611
+				vba_project->offset[i] = macro_info->macro_entry[i].offset;
1612
+				vba_project->length[i] = macro_info->macro_entry[i].len;
1613
+				vba_project->key[i] = macro_info->macro_entry[i].key;
1614
+			}
1615 1615
 		}
1616 1616
 	}
1617 1617
 	/* Fall through */
... ...
@@ -1619,9 +1571,6 @@ abort:
1619 1619
 	if (macro_info) {
1620 1620
 		wm_free_macro_info(macro_info);
1621 1621
 	}
1622
-	if (menu_info) {
1623
-		wm_free_menu_info(menu_info);
1624
-	}
1625 1622
 	if (macro_extnames) {
1626 1623
 		wm_free_extnames(macro_extnames);
1627 1624
 	}
... ...
@@ -1646,7 +1595,7 @@ unsigned char *wm_decrypt_macro(int fd, uint32_t offset, uint32_t len,
1646 1646
 		return NULL;
1647 1647
 	}
1648 1648
 
1649
-	if (cli_readn(fd, buff, len) != (int64_t)len) {
1649
+	if (cli_readn(fd, buff, len) != (int)len) {
1650 1650
 		free(buff);
1651 1651
 		return NULL;
1652 1652
 	}