Tidy up multipart handling

git-svn: trunk@723
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent 058ccefea5
commit f12d249838
  1. 4
      clamav-devel/ChangeLog
  2. 59
      clamav-devel/libclamav/mbox.c
  3. 15
      clamav-devel/libclamav/message.c

@ -1,3 +1,7 @@
Wed Aug 4 19:59:54 BST 2004 (njh)
----------------------------------
* libclamav: Improved the decoding of multipart messages and MIME headers
Wed Aug 4 20:01:26 CEST 2004 (tk) Wed Aug 4 20:01:26 CEST 2004 (tk)
---------------------------------- ----------------------------------
* libclamav: fix compilation error with Sun's compiler (reported by * libclamav: fix compilation error with Sun's compiler (reported by

@ -17,6 +17,9 @@
* *
* Change History: * Change History:
* $Log: mbox.c,v $ * $Log: mbox.c,v $
* Revision 1.91 2004/08/04 18:59:19 nigelhorne
* Tidy up multipart handling
*
* Revision 1.90 2004/07/26 17:02:56 nigelhorne * Revision 1.90 2004/07/26 17:02:56 nigelhorne
* Fix crash when debugging on SPARC * Fix crash when debugging on SPARC
* *
@ -258,7 +261,7 @@
* Compilable under SCO; removed duplicate code with message.c * Compilable under SCO; removed duplicate code with message.c
* *
*/ */
static char const rcsid[] = "$Id: mbox.c,v 1.90 2004/07/26 17:02:56 nigelhorne Exp $"; static char const rcsid[] = "$Id: mbox.c,v 1.91 2004/08/04 18:59:19 nigelhorne Exp $";
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "clamav-config.h" #include "clamav-config.h"
@ -601,7 +604,6 @@ cli_mbox(const char *dir, int desc)
static message * static message *
parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy) parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy)
{ {
bool inContinuationHeader = FALSE; /* state machine: ugh */
bool inHeader = TRUE; bool inHeader = TRUE;
text *t; text *t;
message *ret; message *ret;
@ -640,13 +642,7 @@ parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy)
* a continuation of the previous entry. * a continuation of the previous entry.
*/ */
if(inHeader && buffer && if(inHeader && buffer &&
((buffer[0] == '\t') || (buffer[0] == ' '))) ((buffer[0] == '\t') || (buffer[0] == ' '))) {
inContinuationHeader = TRUE;
if(inContinuationHeader) {
if(!continuationMarker(buffer))
inContinuationHeader = FALSE; /* no more args */
/* /*
* Add all the arguments on the line * Add all the arguments on the line
*/ */
@ -664,11 +660,11 @@ parseEmailHeaders(message *m, const table_t *rfc821Table, bool destroy)
*/ */
if(buffer == NULL) { if(buffer == NULL) {
cli_dbgmsg("End of header information\n"); cli_dbgmsg("End of header information\n");
inContinuationHeader = inHeader = FALSE; inHeader = FALSE;
} else if(parseEmailHeader(ret, buffer, rfc821Table) == CONTENT_TYPE) } else {
inContinuationHeader = continuationMarker(buffer); (void)parseEmailHeader(ret, buffer, rfc821Table);
if(buffer)
free(buffer); free(buffer);
}
} else { } else {
/*cli_dbgmsg("Add line to body '%s'\n", buffer);*/ /*cli_dbgmsg("Add line to body '%s'\n", buffer);*/
if(messageAddLine(ret, buffer, 0) < 0) if(messageAddLine(ret, buffer, 0) < 0)
@ -731,9 +727,8 @@ parseEmailHeader(message *m, const char *line, const table_t *rfc821Table)
* This function parses the body of mainMessage and saves its attachments in dir * This function parses the body of mainMessage and saves its attachments in dir
* *
* mainMessage is the buffer to be parsed, it contains an e-mail's body, without * mainMessage is the buffer to be parsed, it contains an e-mail's body, without
* any headers. First * any headers. First time of calling it'll be
* time of calling it'll be * the whole message. Later it'll be parts of a multipart message
* the whole message. Later it'll be parts of a multipart message
* textIn is the plain text message being built up so far * textIn is the plain text message being built up so far
* blobsIn contains the array of attachments found so far * blobsIn contains the array of attachments found so far
* *
@ -876,10 +871,8 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
message **m; message **m;
m = cli_realloc(messages, ((multiparts + 1) * sizeof(message *))); m = cli_realloc(messages, ((multiparts + 1) * sizeof(message *)));
if(m == NULL) { if(m == NULL)
multiparts--;
break; break;
}
messages = m; messages = m;
aMessage = messages[multiparts] = messageCreate(); aMessage = messages[multiparts] = messageCreate();
@ -1164,7 +1157,9 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
bool addAttachment = FALSE; bool addAttachment = FALSE;
bool addToText = FALSE; bool addToText = FALSE;
const char *dtype; const char *dtype;
#if 0
message *body; message *body;
#endif
aMessage = messages[i]; aMessage = messages[i];
@ -1320,6 +1315,7 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
* be an attachment * be an attachment
*/ */
cli_dbgmsg("Found multipart inside multipart\n"); cli_dbgmsg("Found multipart inside multipart\n");
#if 0
if(aMessage) { if(aMessage) {
body = parseEmailHeaders(aMessage, rfc821Table, TRUE); body = parseEmailHeaders(aMessage, rfc821Table, TRUE);
if(body) { if(body) {
@ -1339,6 +1335,18 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
mainMessage = body; mainMessage = body;
} }
#else
if(aMessage) {
/*
* The headers were parsed when reading in the
* whole multipart section
*/
rc = parseEmailBody(aMessage, blobs, nBlobs, aText, dir, rfc821Table, subtypeTable);
cli_dbgmsg("Finished recursion\n");
assert(aMessage == messages[i]);
messageDestroy(messages[i]);
messages[i] = NULL;
#endif
} else { } else {
rc = parseEmailBody(NULL, blobs, nBlobs, NULL, dir, rfc821Table, subtypeTable); rc = parseEmailBody(NULL, blobs, nBlobs, NULL, dir, rfc821Table, subtypeTable);
if(mainMessage && (mainMessage != messageIn)) if(mainMessage && (mainMessage != messageIn))
@ -1598,6 +1606,11 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
} }
} }
if(aText && (textIn == NULL)) {
textDestroy(aText);
aText = NULL;
}
cli_dbgmsg("%d attachments found\n", nBlobs); cli_dbgmsg("%d attachments found\n", nBlobs);
if(nBlobs == 0) { if(nBlobs == 0) {
@ -1719,6 +1732,9 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
if(saveIt) { if(saveIt) {
cli_dbgmsg("Saving text part to scan\n"); cli_dbgmsg("Saving text part to scan\n");
/*
* TODO: May be better to save aText
*/
saveTextPart(mainMessage, dir); saveTextPart(mainMessage, dir);
} }
} }
@ -1739,9 +1755,6 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
} }
} }
if(aText && (textIn == NULL))
textDestroy(aText);
/* Already done */ /* Already done */
if(blobs && (blobsIn == NULL)) if(blobs && (blobsIn == NULL))
blobArrayDestroy(blobs, nBlobs); blobArrayDestroy(blobs, nBlobs);
@ -1980,7 +1993,7 @@ continuationMarker(const char *line)
static int static int
parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const char *arg) parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const char *arg)
{ {
int type = tableFind(rfc821Table, cmd); const int type = tableFind(rfc821Table, cmd);
#ifdef CL_THREAD_SAFE #ifdef CL_THREAD_SAFE
char *strptr; char *strptr;
#endif #endif

@ -17,6 +17,9 @@
* *
* Change History: * Change History:
* $Log: message.c,v $ * $Log: message.c,v $
* Revision 1.69 2004/08/04 18:59:19 nigelhorne
* Tidy up multipart handling
*
* Revision 1.68 2004/07/30 11:50:39 nigelhorne * Revision 1.68 2004/07/30 11:50:39 nigelhorne
* Code tidy * Code tidy
* *
@ -201,7 +204,7 @@
* uuencodebegin() no longer static * uuencodebegin() no longer static
* *
*/ */
static char const rcsid[] = "$Id: message.c,v 1.68 2004/07/30 11:50:39 nigelhorne Exp $"; static char const rcsid[] = "$Id: message.c,v 1.69 2004/08/04 18:59:19 nigelhorne Exp $";
#if HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "clamav-config.h" #include "clamav-config.h"
@ -658,12 +661,22 @@ messageAddArguments(message *m, const char *s)
*ptr = '\0'; *ptr = '\0';
#if 0
field = cli_malloc(strlen(key) + strlen(data) + 2); field = cli_malloc(strlen(key) + strlen(data) + 2);
if(field) if(field)
sprintf(field, "%s=%s", key, data); sprintf(field, "%s=%s", key, data);
free((char *)key); free((char *)key);
free(data); free(data);
#else
field = cli_realloc((char *)key, strlen(key) + strlen(data) + 2);
if(field) {
strcat(field, "=");
strcat(field, data);
} else
free((char *)key);
free(data);
#endif
} else { } else {
size_t len; size_t len;

Loading…
Cancel
Save