Browse code

Remove compiler warning

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

Nigel Horne authored on 2005/12/17 00:47:55
Showing 1 changed files
... ...
@@ -24,7 +24,7 @@
24 24
 #include "clamav-config.h"
25 25
 #endif
26 26
 
27
-static	char	const	rcsid[] = "$Id: tnef.c,v 1.28 2005/11/03 21:45:18 kojm Exp $";
27
+static	char	const	rcsid[] = "$Id: tnef.c,v 1.29 2005/12/16 15:47:55 nigelhorne Exp $";
28 28
 
29 29
 #include <stdio.h>
30 30
 #include <fcntl.h>
... ...
@@ -102,9 +102,9 @@ cli_tnef(const char *dir, int desc)
102 102
 	alldone = 0;
103 103
 
104 104
 	do {
105
-		uint8_t part;
106
-		uint16_t type, tag;
107
-		int32_t length;
105
+		uint8_t part = 0;
106
+		uint16_t type = 0, tag = 0;
107
+		int32_t length = 0;
108 108
 
109 109
 		switch(tnef_header(fp, &part, &type, &tag, &length)) {
110 110
 			case 0:
... ...
@@ -121,6 +121,13 @@ cli_tnef(const char *dir, int desc)
121 121
 				alldone = 1;
122 122
 				break;
123 123
 		}
124
+		if(length == 0)
125
+			continue;
126
+		if(length < 0) {
127
+			cli_warnmsg("Corrupt TNEF header detected - length %d\n", length);
128
+			ret = CL_EFORMAT;
129
+			break;
130
+		}
124 131
 		if(alldone)
125 132
 			break;
126 133
 		switch(part) {
... ...
@@ -203,7 +210,7 @@ static int
203 203
 tnef_message(FILE *fp, uint16_t type, uint16_t tag, int32_t length)
204 204
 {
205 205
 	uint16_t i16;
206
-	/* off_t offset; */
206
+	off_t offset;
207 207
 #if	CL_DEBUG
208 208
 	uint32_t i32;
209 209
 	char *string;
... ...
@@ -211,7 +218,7 @@ tnef_message(FILE *fp, uint16_t type, uint16_t tag, int32_t length)
211 211
 
212 212
 	cli_dbgmsg("message tag 0x%x, type 0x%x, length %d\n", tag, type, length);
213 213
 
214
-	/* offset = ftell(fp); */
214
+	offset = ftell(fp);
215 215
 
216 216
 	/*
217 217
 	 * a lot of this stuff should be only discovered in debug mode...
... ...
@@ -261,11 +268,11 @@ tnef_message(FILE *fp, uint16_t type, uint16_t tag, int32_t length)
261 261
 
262 262
 	/*cli_dbgmsg("%lu %lu\n", (long)(offset + length), ftell(fp));*/
263 263
 
264
-	/* fseek(fp, offset + length, SEEK_SET); */
264
+	fseek(fp, offset + length, SEEK_SET);
265 265
 
266 266
 	/* Checksum - TODO, verify */
267
-	/* if(fread(&i16, sizeof(uint16_t), 1, fp) != 1)
268
-		return -1; */
267
+	if(fread(&i16, sizeof(uint16_t), 1, fp) != 1)
268
+		return -1;
269 269
 
270 270
 	return 0;
271 271
 }
... ...
@@ -275,12 +282,12 @@ tnef_attachment(FILE *fp, uint16_t type, uint16_t tag, int32_t length, const cha
275 275
 {
276 276
 	uint32_t todo;
277 277
 	uint16_t i16;
278
-	/* off_t offset; */
278
+	off_t offset;
279 279
 	char *string;
280 280
 
281 281
 	cli_dbgmsg("attachment tag 0x%x, type 0x%x, length %d\n", tag, type, length);
282 282
 
283
-	/* offset = ftell(fp); */
283
+	offset = ftell(fp);
284 284
 
285 285
 	switch(tag) {
286 286
 		case attATTACHTITLE:
... ...
@@ -336,11 +343,11 @@ tnef_attachment(FILE *fp, uint16_t type, uint16_t tag, int32_t length, const cha
336 336
 
337 337
 	/*cli_dbgmsg("%lu %lu\n", (long)(offset + length), ftell(fp));*/
338 338
 
339
-	/* fseek(fp, (long)(offset + length), SEEK_SET); */	/* shouldn't be needed */
339
+	fseek(fp, (long)(offset + length), SEEK_SET);	/* shouldn't be needed */
340 340
 
341 341
 	/* Checksum - TODO, verify */
342
-	/* if(fread(&i16, sizeof(uint16_t), 1, fp) != 1) 
343
-		return -1; */
342
+	if(fread(&i16, sizeof(uint16_t), 1, fp) != 1) 
343
+		return -1;
344 344
 
345 345
 	return 0;
346 346
 }
... ...
@@ -360,8 +367,8 @@ tnef_header(FILE *fp, uint8_t *part, uint16_t *type, uint16_t *tag, int32_t *len
360 360
 		return -1;
361 361
 
362 362
 	i32 = host32(i32);
363
-	*tag = i32 & 0xFFFF;
364
-	*type = (i32 & 0xFFFF0000) >> 16;
363
+	*tag = (uint16_t)(i32 & 0xFFFF);
364
+	*type = (uint16_t)((i32 & 0xFFFF0000) >> 16);
365 365
 
366 366
 	if(fread(&i32, sizeof(uint32_t), 1, fp) != 1)
367 367
 		return -1;