git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1024 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/10/19 22:57:26... | ... |
@@ -1,3 +1,9 @@ |
1 |
+Tue Oct 19 14:56:27 BST 2004 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/message.c: Some base64 encoders encode extra NUL bytes |
|
4 |
+ at the end - ensure that they aren't added when |
|
5 |
+ decoding |
|
6 |
+ |
|
1 | 7 |
Tue Oct 19 02:53:46 CEST 2004 (tk) |
2 | 8 |
---------------------------------- |
3 | 9 |
* libclamav/matcher.c: fix signature target type validation for data files |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: message.c,v $ |
20 |
+ * Revision 1.104 2004/10/19 13:53:55 nigelhorne |
|
21 |
+ * Don't add trailing NUL bytes |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.103 2004/10/17 09:29:21 nigelhorne |
21 | 24 |
* Advise to report broken emails |
22 | 25 |
* |
... | ... |
@@ -306,7 +309,7 @@ |
306 | 306 |
* uuencodebegin() no longer static |
307 | 307 |
* |
308 | 308 |
*/ |
309 |
-static char const rcsid[] = "$Id: message.c,v 1.103 2004/10/17 09:29:21 nigelhorne Exp $"; |
|
309 |
+static char const rcsid[] = "$Id: message.c,v 1.104 2004/10/19 13:53:55 nigelhorne Exp $"; |
|
310 | 310 |
|
311 | 311 |
#if HAVE_CONFIG_H |
312 | 312 |
#include "clamav-config.h" |
... | ... |
@@ -405,7 +408,7 @@ static struct mime_map { |
405 | 405 |
#define USE_TABLE /* table driven base64 decoder */ |
406 | 406 |
|
407 | 407 |
#ifdef USE_TABLE |
408 |
-static unsigned char base64Table[256] = { |
|
408 |
+static const unsigned char base64Table[256] = { |
|
409 | 409 |
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, |
410 | 410 |
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, |
411 | 411 |
255,255,255,255,255,255,255,255,255,255,255,62,255,255,255,63, |
... | ... |
@@ -1522,6 +1525,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy |
1522 | 1522 |
|
1523 | 1523 |
for(i = 0; i < m->numberOfEncTypes; i++) { |
1524 | 1524 |
encoding_type enctype = m->encodingTypes[i]; |
1525 |
+ size_t size; |
|
1525 | 1526 |
|
1526 | 1527 |
/* |
1527 | 1528 |
* Find the filename to decode |
... | ... |
@@ -1612,6 +1616,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy |
1612 | 1612 |
continue; |
1613 | 1613 |
} |
1614 | 1614 |
|
1615 |
+ size = 0; |
|
1615 | 1616 |
do { |
1616 | 1617 |
unsigned char data[1024]; |
1617 | 1618 |
unsigned char *uptr; |
... | ... |
@@ -1639,8 +1644,10 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy |
1639 | 1639 |
|
1640 | 1640 |
assert(uptr <= &data[sizeof(data)]); |
1641 | 1641 |
|
1642 |
- if(uptr != data) |
|
1642 |
+ if(uptr != data) { |
|
1643 | 1643 |
(*addData)(ret, data, (size_t)(uptr - data)); |
1644 |
+ size += (size_t)(uptr - data); |
|
1645 |
+ } |
|
1644 | 1646 |
|
1645 | 1647 |
/* |
1646 | 1648 |
* According to RFC1521, '=' is used to pad out |
... | ... |
@@ -1654,6 +1661,8 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy |
1654 | 1654 |
break;*/ |
1655 | 1655 |
|
1656 | 1656 |
} while((t_line = t_line->t_next) != NULL); |
1657 |
+ |
|
1658 |
+ cli_dbgmsg("Exported %u bytes\n", size); |
|
1657 | 1659 |
} |
1658 | 1660 |
|
1659 | 1661 |
/* Verify we have nothing left to flush out */ |
... | ... |
@@ -2077,12 +2086,12 @@ decodeLine(message *m, encoding_type et, const char *line, unsigned char *buf, s |
2077 | 2077 |
if(copy == NULL) |
2078 | 2078 |
break; |
2079 | 2079 |
|
2080 |
- sanitiseBase64(copy); |
|
2081 |
- |
|
2082 | 2080 |
p2 = strchr(copy, '='); |
2083 | 2081 |
if(p2) |
2084 | 2082 |
*p2 = '\0'; |
2085 | 2083 |
|
2084 |
+ sanitiseBase64(copy); |
|
2085 |
+ |
|
2086 | 2086 |
/* |
2087 | 2087 |
* Klez doesn't always put "=" on the last line |
2088 | 2088 |
*/ |
... | ... |
@@ -2148,6 +2157,7 @@ decodeLine(message *m, encoding_type et, const char *line, unsigned char *buf, s |
2148 | 2148 |
static void |
2149 | 2149 |
sanitiseBase64(char *s) |
2150 | 2150 |
{ |
2151 |
+#ifdef USE_TABLE |
|
2151 | 2152 |
for(; *s; s++) |
2152 | 2153 |
if(base64Table[*s] == 255) { |
2153 | 2154 |
char *p1; |
... | ... |
@@ -2155,6 +2165,26 @@ sanitiseBase64(char *s) |
2155 | 2155 |
for(p1 = s; p1[0] != '\0'; p1++) |
2156 | 2156 |
p1[0] = p1[1]; |
2157 | 2157 |
} |
2158 |
+#else |
|
2159 |
+ for(; *s; s++) { |
|
2160 |
+ char *p1; |
|
2161 |
+ char c = *s; |
|
2162 |
+ |
|
2163 |
+ if(isupper(c)) |
|
2164 |
+ continue; |
|
2165 |
+ if(isdigit(c)) |
|
2166 |
+ continue; |
|
2167 |
+ if(c == '+') |
|
2168 |
+ continue; |
|
2169 |
+ if(c == '/') |
|
2170 |
+ continue; |
|
2171 |
+ if(islower(c)) |
|
2172 |
+ continue; |
|
2173 |
+ |
|
2174 |
+ for(p1 = s; p1[0] != '\0'; p1++) |
|
2175 |
+ p1[0] = p1[1]; |
|
2176 |
+ } |
|
2177 |
+#endif |
|
2158 | 2178 |
} |
2159 | 2179 |
|
2160 | 2180 |
/* |
... | ... |
@@ -2212,23 +2242,32 @@ decode(message *m, const char *in, unsigned char *out, unsigned char (*decoder)( |
2212 | 2212 |
} |
2213 | 2213 |
else { |
2214 | 2214 |
if(in == NULL) { /* flush */ |
2215 |
- int nbytes = m->base64chars; |
|
2215 |
+ int nbytes; |
|
2216 | 2216 |
|
2217 |
- if(nbytes == 0) |
|
2217 |
+ if(m->base64chars == 0) |
|
2218 | 2218 |
return out; |
2219 | 2219 |
|
2220 |
+ cli_dbgmsg("base64chars = %d (%c %c %c)\n", m->base64chars, |
|
2221 |
+ cb1 ? cb1 : '@', |
|
2222 |
+ cb2 ? cb2 : '@', |
|
2223 |
+ cb3 ? cb3 : '@'); |
|
2224 |
+ |
|
2220 | 2225 |
m->base64chars--; |
2221 | 2226 |
b1 = cb1; |
2227 |
+ nbytes = 1; |
|
2222 | 2228 |
|
2223 | 2229 |
if(m->base64chars) { |
2224 | 2230 |
m->base64chars--; |
2225 | 2231 |
b2 = cb2; |
2226 | 2232 |
|
2227 | 2233 |
if(m->base64chars) { |
2234 |
+ nbytes++; |
|
2228 | 2235 |
m->base64chars--; |
2229 | 2236 |
b3 = cb3; |
2230 |
- assert(m->base64chars == 0); |
|
2231 |
- } |
|
2237 |
+ if(b3) |
|
2238 |
+ nbytes++; |
|
2239 |
+ } else if(b2) |
|
2240 |
+ nbytes++; |
|
2232 | 2241 |
} |
2233 | 2242 |
|
2234 | 2243 |
switch(nbytes) { |