git-svn: trunk@3559
Nigel Horne authored on 2008/01/30 03:11:28... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Tue Jan 29 17:50:05 GMT 2008 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/tnef.c: Handle trailing CR and change handling of truncated |
|
4 |
+ files (Based on a Patch from Edwin) |
|
5 |
+ |
|
1 | 6 |
Tue Jan 29 17:10:54 GMT 2008 (njh) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav/mbox.c: Downgrade some messages from warning to debug |
... | ... |
@@ -60,6 +60,8 @@ static int tnef_header(FILE *fp, uint8_t *part, uint16_t *type, uint16_t *tag, i |
60 | 60 |
#define host16(v) le16_to_host(v) |
61 | 61 |
#define host32(v) le32_to_host(v) |
62 | 62 |
|
63 |
+/* a TNEF file must be at least this size */ |
|
64 |
+#define MIN_SIZE (sizeof(uint32_t) + sizeof(uint16_t)) |
|
63 | 65 |
|
64 | 66 |
int |
65 | 67 |
cli_tnef(const char *dir, int desc) |
... | ... |
@@ -80,6 +82,11 @@ cli_tnef(const char *dir, int desc) |
80 | 80 |
} |
81 | 81 |
fsize = statb.st_size; |
82 | 82 |
|
83 |
+ if(fsize < MIN_SIZE) { |
|
84 |
+ cli_dbgmsg("cli_tngs: file too small, ignoring\n"); |
|
85 |
+ return CL_CLEAN; |
|
86 |
+ } |
|
87 |
+ |
|
83 | 88 |
i = dup(desc); |
84 | 89 |
if((fp = fdopen(i, "rb")) == NULL) { |
85 | 90 |
cli_errmsg("Can't open descriptor %d\n", desc); |
... | ... |
@@ -89,6 +96,7 @@ cli_tnef(const char *dir, int desc) |
89 | 89 |
|
90 | 90 |
if(fread(&i32, sizeof(uint32_t), 1, fp) != 1) { |
91 | 91 |
fclose(fp); |
92 |
+ /* The file is at least MIN_SIZE bytes, so it "can't" fail */ |
|
92 | 93 |
return CL_EIO; |
93 | 94 |
} |
94 | 95 |
if(host32(i32) != TNEF_SIGNATURE) { |
... | ... |
@@ -98,6 +106,7 @@ cli_tnef(const char *dir, int desc) |
98 | 98 |
|
99 | 99 |
if(fread(&i16, sizeof(uint16_t), 1, fp) != 1) { |
100 | 100 |
fclose(fp); |
101 |
+ /* The file is at least MIN_SIZE bytes, so it "can't" fail */ |
|
101 | 102 |
return CL_EIO; |
102 | 103 |
} |
103 | 104 |
|
... | ... |
@@ -121,7 +130,12 @@ cli_tnef(const char *dir, int desc) |
121 | 121 |
case 1: |
122 | 122 |
break; |
123 | 123 |
default: |
124 |
- ret = CL_EIO; |
|
124 |
+ /* |
|
125 |
+ * Assume truncation, not file I/O error |
|
126 |
+ */ |
|
127 |
+ /*ret = CL_EIO;*/ |
|
128 |
+ cli_warnmsg("cli_tnef: file truncated, returning CLEAN\n"); |
|
129 |
+ ret = CL_CLEAN; |
|
125 | 130 |
alldone = 1; |
126 | 131 |
break; |
127 | 132 |
} |
... | ... |
@@ -382,7 +396,7 @@ tnef_header(FILE *fp, uint8_t *part, uint16_t *type, uint16_t *tag, int32_t *len |
382 | 382 |
return 0; |
383 | 383 |
|
384 | 384 |
if(fread(&i32, sizeof(uint32_t), 1, fp) != 1) { |
385 |
- if((*part == '\n') && feof(fp)) { |
|
385 |
+ if(((*part == '\n') || (*part == '\r')) && feof(fp)) { |
|
386 | 386 |
/* |
387 | 387 |
* trailing newline in the file, could be caused by |
388 | 388 |
* broken quoted-printable encoding in the source |