git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1141 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/11/29 06:05:50... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: binhex.c,v $ |
20 |
+ * Revision 1.8 2004/11/28 21:05:50 nigelhorne |
|
21 |
+ * Handle headers with only spaces |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.7 2004/11/23 09:05:26 nigelhorne |
21 | 24 |
* Fix crash in base64 encoded binhex files |
22 | 25 |
* |
... | ... |
@@ -36,7 +39,7 @@ |
36 | 36 |
* First draft of binhex.c |
37 | 37 |
* |
38 | 38 |
*/ |
39 |
-static char const rcsid[] = "$Id: binhex.c,v 1.7 2004/11/23 09:05:26 nigelhorne Exp $"; |
|
39 |
+static char const rcsid[] = "$Id: binhex.c,v 1.8 2004/11/28 21:05:50 nigelhorne Exp $"; |
|
40 | 40 |
|
41 | 41 |
#include "clamav.h" |
42 | 42 |
|
... | ... |
@@ -124,7 +127,7 @@ cli_binhex(const char *dir, int desc) |
124 | 124 |
|
125 | 125 |
/*puts(line);*/ |
126 | 126 |
|
127 |
- if(messageAddStr(m, line) < 0) |
|
127 |
+ if(messageAddStr(m, line, 1) < 0) |
|
128 | 128 |
break; |
129 | 129 |
|
130 | 130 |
buf = ++ptr; |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: mbox.c,v $ |
20 |
+ * Revision 1.193 2004/11/28 21:05:50 nigelhorne |
|
21 |
+ * Handle headers with only spaces |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.192 2004/11/28 16:27:28 nigelhorne |
21 | 24 |
* Save the text portions as text not mail files |
22 | 25 |
* |
... | ... |
@@ -564,7 +567,7 @@ |
564 | 564 |
* Compilable under SCO; removed duplicate code with message.c |
565 | 565 |
* |
566 | 566 |
*/ |
567 |
-static char const rcsid[] = "$Id: mbox.c,v 1.192 2004/11/28 16:27:28 nigelhorne Exp $"; |
|
567 |
+static char const rcsid[] = "$Id: mbox.c,v 1.193 2004/11/28 21:05:50 nigelhorne Exp $"; |
|
568 | 568 |
|
569 | 569 |
#if HAVE_CONFIG_H |
570 | 570 |
#include "clamav-config.h" |
... | ... |
@@ -952,12 +955,14 @@ cli_mbox(const char *dir, int desc, unsigned int options) |
952 | 952 |
cli_dbgmsg("Finished processing message\n"); |
953 | 953 |
} else |
954 | 954 |
lastLineWasEmpty = (bool)(buffer[0] == '\0'); |
955 |
- if(messageAddStr(m, buffer) < 0) |
|
955 |
+ if(messageAddStr(m, buffer, 1) < 0) |
|
956 | 956 |
break; |
957 | 957 |
} while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL); |
958 | 958 |
|
959 | 959 |
cli_dbgmsg("Deal with email number %d\n", messagenumber); |
960 | 960 |
} else { |
961 |
+ int inHeader = 1; |
|
962 |
+ |
|
961 | 963 |
/* |
962 | 964 |
* It's a single message, parse the headers then the body |
963 | 965 |
* Ignore blank lines at the start of the message |
... | ... |
@@ -977,13 +982,15 @@ cli_mbox(const char *dir, int desc, unsigned int options) |
977 | 977 |
(fgets(buffer, sizeof(buffer) - 1, fd) != NULL)) |
978 | 978 |
; |
979 | 979 |
|
980 |
- buffer[LINE_LENGTH] = '\0'; |
|
980 |
+ buffer[sizeof(buffer) - 1] = '\0'; |
|
981 | 981 |
|
982 | 982 |
/* |
983 | 983 |
* FIXME: files full of new lines and nothing else are |
984 | 984 |
* handled ungracefully... |
985 | 985 |
*/ |
986 | 986 |
do { |
987 |
+ const char *ptr; |
|
988 |
+ |
|
987 | 989 |
/* |
988 | 990 |
* TODO: this needlessly creates a message object, |
989 | 991 |
* it'd be better if parseEmailHeaders could also |
... | ... |
@@ -992,8 +999,22 @@ cli_mbox(const char *dir, int desc, unsigned int options) |
992 | 992 |
* of code I want to avoid |
993 | 993 |
*/ |
994 | 994 |
(void)cli_chomp(buffer); |
995 |
- if(messageAddStr(m, buffer) < 0) |
|
995 |
+ |
|
996 |
+ /* |
|
997 |
+ * Ignore leading CR, e.g. if newlines are LFCR instead |
|
998 |
+ * or CRLF |
|
999 |
+ */ |
|
1000 |
+ for(ptr = buffer; *ptr == '\r'; ptr++) |
|
1001 |
+ ; |
|
1002 |
+ /* |
|
1003 |
+ * Don't blank lines which are only spaces from |
|
1004 |
+ * headers, otherwise they'll be treated as the end of |
|
1005 |
+ * header marker |
|
1006 |
+ */ |
|
1007 |
+ if(messageAddStr(m, ptr, !inHeader) < 0) |
|
996 | 1008 |
break; |
1009 |
+ if(*ptr == '\n') |
|
1010 |
+ inHeader = 0; |
|
997 | 1011 |
} while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL); |
998 | 1012 |
} |
999 | 1013 |
|
... | ... |
@@ -1500,7 +1521,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t |
1500 | 1500 |
do { |
1501 | 1501 |
const char *line = lineGetData(t_line->t_line); |
1502 | 1502 |
|
1503 |
- /*printf("inMimeHead %d inhead %d boundary '%s' line '%s' next '%s'\n", |
|
1503 |
+ /*cli_dbgmsg("inMimeHead %d inhead %d boundary '%s' line '%s' next '%s'\n", |
|
1504 | 1504 |
inMimeHead, inhead, boundary, line, |
1505 | 1505 |
t_line->t_next && t_line->t_next->t_line ? lineGetData(t_line->t_next->t_line) : "(null)");*/ |
1506 | 1506 |
|
... | ... |
@@ -1884,7 +1905,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t |
1884 | 1884 |
/* |
1885 | 1885 |
* No plain text version |
1886 | 1886 |
*/ |
1887 |
- messageAddStr(aMessage, "No plain text alternative"); |
|
1887 |
+ messageAddStr(aMessage, "No plain text alternative", 0); |
|
1888 | 1888 |
assert(messageGetBody(aMessage) != NULL); |
1889 | 1889 |
break; |
1890 | 1890 |
case TEXT: |
... | ... |
@@ -2945,7 +2966,7 @@ rfc2047(const char *in) |
2945 | 2945 |
m = messageCreate(); |
2946 | 2946 |
if(m == NULL) |
2947 | 2947 |
break; |
2948 |
- messageAddStr(m, enctext); |
|
2948 |
+ messageAddStr(m, enctext, 0); |
|
2949 | 2949 |
free(enctext); |
2950 | 2950 |
switch(encoding) { |
2951 | 2951 |
case 'q': |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: message.c,v $ |
20 |
+ * Revision 1.125 2004/11/28 21:05:49 nigelhorne |
|
21 |
+ * Handle headers with only spaces |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.124 2004/11/28 16:24:12 nigelhorne |
21 | 24 |
* Allow lowercase hex characters in quoted-printable |
22 | 25 |
* |
... | ... |
@@ -369,7 +372,7 @@ |
369 | 369 |
* uuencodebegin() no longer static |
370 | 370 |
* |
371 | 371 |
*/ |
372 |
-static char const rcsid[] = "$Id: message.c,v 1.124 2004/11/28 16:24:12 nigelhorne Exp $"; |
|
372 |
+static char const rcsid[] = "$Id: message.c,v 1.125 2004/11/28 21:05:49 nigelhorne Exp $"; |
|
373 | 373 |
|
374 | 374 |
#if HAVE_CONFIG_H |
375 | 375 |
#include "clamav-config.h" |
... | ... |
@@ -1125,12 +1128,13 @@ messageAddLine(message *m, line_t *line) |
1125 | 1125 |
* Line must not be terminated by a \n |
1126 | 1126 |
*/ |
1127 | 1127 |
int |
1128 |
-messageAddStr(message *m, const char *data) |
|
1128 |
+messageAddStr(message *m, const char *data, int stripSpaces) |
|
1129 | 1129 |
{ |
1130 | 1130 |
line_t *repeat = NULL; |
1131 | 1131 |
|
1132 | 1132 |
assert(m != NULL); |
1133 | 1133 |
|
1134 |
+#if 0 /* Not sure why this doesn't work, it would save some RAM */ |
|
1134 | 1135 |
if(data) { |
1135 | 1136 |
int iswhite = 1; |
1136 | 1137 |
const char *p; |
... | ... |
@@ -1142,9 +1146,25 @@ messageAddStr(message *m, const char *data) |
1142 | 1142 |
} |
1143 | 1143 |
if(iswhite) { |
1144 | 1144 |
/*cli_dbgmsg("messageAddStr: empty line: '%s'\n", data);*/ |
1145 |
+ data = (stripSpaces) ? NULL : " "; |
|
1146 |
+ } |
|
1147 |
+ } |
|
1148 |
+#else |
|
1149 |
+ if(stripSpaces && data) { |
|
1150 |
+ int iswhite = 1; |
|
1151 |
+ const char *p; |
|
1152 |
+ |
|
1153 |
+ for(p = data; *p != '\0'; p++) |
|
1154 |
+ if(!isspace(*p)) { |
|
1155 |
+ iswhite = 0; |
|
1156 |
+ break; |
|
1157 |
+ } |
|
1158 |
+ if(iswhite) { |
|
1159 |
+ /*cli_dbgmsg("messageAddStr: empty line: '%s'\n", data);*/ |
|
1145 | 1160 |
data = NULL; |
1146 | 1161 |
} |
1147 | 1162 |
} |
1163 |
+#endif |
|
1148 | 1164 |
|
1149 | 1165 |
if(m->body_first == NULL) |
1150 | 1166 |
m->body_last = m->body_first = (text *)cli_malloc(sizeof(text)); |
... | ... |
@@ -16,6 +16,9 @@ |
16 | 16 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | 17 |
* |
18 | 18 |
* $Log: message.h,v $ |
19 |
+ * Revision 1.23 2004/11/28 21:05:50 nigelhorne |
|
20 |
+ * Handle headers with only spaces |
|
21 |
+ * |
|
19 | 22 |
* Revision 1.22 2004/11/22 15:18:51 nigelhorne |
20 | 23 |
* Performance work |
21 | 24 |
* |
... | ... |
@@ -117,7 +120,7 @@ const char *messageFindArgument(const message *m, const char *variable); |
117 | 117 |
void messageSetEncoding(message *m, const char *enctype); |
118 | 118 |
encoding_type messageGetEncoding(const message *m); |
119 | 119 |
int messageAddLine(message *m, line_t *line); |
120 |
-int messageAddStr(message *m, const char *data); |
|
120 |
+int messageAddStr(message *m, const char *data, int stripSpaces); |
|
121 | 121 |
int messageAddStrAtTop(message *m, const char *data); |
122 | 122 |
const text *messageGetBody(const message *m); |
123 | 123 |
void messageClean(message *m); |