Handle yEnc attachments

git-svn: trunk@890
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent 6d3125693d
commit 16394c6d1a
  1. 4
      clamav-devel/ChangeLog
  2. 67
      clamav-devel/libclamav/message.c
  3. 5
      clamav-devel/libclamav/message.h

@ -1,3 +1,7 @@
Fri Sep 17 14:47:53 BST 2004 (njh)
----------------------------------
* libclamav: Scan yEnc mime attachments
Fri Sep 17 11:56:58 BST 2004 (njh)
----------------------------------
* libclamav: Handle even more attempts to falsify the mime type

@ -17,6 +17,9 @@
*
* Change History:
* $Log: message.c,v $
* Revision 1.85 2004/09/17 13:47:19 nigelhorne
* Handle yEnc attachments
*
* Revision 1.84 2004/09/17 09:48:53 nigelhorne
* Handle attempts to hide mime type
*
@ -249,7 +252,7 @@
* uuencodebegin() no longer static
*
*/
static char const rcsid[] = "$Id: message.c,v 1.84 2004/09/17 09:48:53 nigelhorne Exp $";
static char const rcsid[] = "$Id: message.c,v 1.85 2004/09/17 13:47:19 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -326,6 +329,7 @@ static const struct encoding_map {
{ "8bit", EIGHTBIT },
{ "8 bit", EIGHTBIT }, /* incorrect */
{ "x-uuencode", UUENCODE },
{ "x-yencode", YENCODE },
{ "binary", BINARY },
{ NULL, NOENCODING }
};
@ -1027,6 +1031,8 @@ messageIsEncoding(message *m)
(isdigit(line[8])) &&
(line[9] == ' ')))
m->uuencode = m->body_last;
else if((m->yenc == NULL) && (strncmp(line, "=ybegin line=", 13) == 0))
m->yenc = m->body_last;
}
/*
@ -1402,6 +1408,27 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
(*setFilename)(ret, dir, filename);
t_line = t_line->t_next;
enctype = UUENCODE;
} else if((enctype == YENCODE) || ((i == 0) && yEncBegin(m))) {
/*
* TODO: handle multipart yEnc encoded files
*/
t_line = yEncBegin(m);
filename = lineGetData(t_line->t_line);
if((filename = strstr(filename, " name=")) != NULL) {
filename = strdup(&filename[6]);
if(filename) {
cli_chomp(filename);
strstrip(filename);
cli_dbgmsg("Set yEnc filename to \"%s\"\n", filename);
}
} else
filename = strdup("attachment");
if(filename)
(*setFilename)(ret, dir, filename);
t_line = t_line->t_next;
enctype = YENCODE;
} else {
filename = (char *)messageFindArgument(m, "filename");
if(filename == NULL) {
@ -1423,7 +1450,8 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
t_line = messageGetBody(m);
}
free((char *)filename);
if(filename)
free((char *)filename);
/*
* t_line should now point to the first (encoded) line of the message
@ -1455,6 +1483,11 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
continue;
if(strcasecmp(line, "end") == 0)
break;
} else if(enctype == YENCODE) {
if(line == NULL)
continue;
if(strncmp(line, "=end ", 5) == 0)
break;
}
uptr = decodeLine(m, enctype, line, data, sizeof(data));
@ -1593,6 +1626,16 @@ messageToText(message *m)
return NULL;
}
t_line = t_line->t_next;
} else if(enctype == YENCODE) {
t_line = yEncBegin(m);
if(t_line == NULL) {
/*cli_warnmsg("YENCODED attachment is missing begin statement\n");*/
if(first)
textDestroy(first);
return NULL;
}
t_line = t_line->t_next;
} else {
if((i == 0) && binhexBegin(m))
cli_warnmsg("Binhex messages not supported yet.\n");
@ -1698,6 +1741,12 @@ uuencodeBegin(const message *m)
}
#endif
const text *
yEncBegin(const message *m)
{
return m->yenc;
}
/*
* Scan to find the BINHEX message (if any)
*/
@ -1910,6 +1959,20 @@ decodeLine(message *m, encoding_type et, const char *line, unsigned char *buf, s
else
buf = decode(m, line, buf, uudecode, (len & 3) == 0);
break;
case YENCODE:
if((line == NULL) || (*line == '\0')) /* empty line */
break;
if(strncmp(line, "=yend ", 6) == 0)
break;
while(*line)
if(*line == '=') {
if(*++line == '\0')
break;
*buf++ = ((*line++ - 64) & 255);
} else
*buf++ = ((*line++ - 42) & 255);
break;
}
*buf = '\0';

@ -16,6 +16,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: message.h,v $
* Revision 1.19 2004/09/17 13:47:19 nigelhorne
* Handle yEnc attachments
*
* Revision 1.18 2004/09/17 09:48:53 nigelhorne
* Handle attempts to hide mime type
*
@ -85,6 +88,7 @@ typedef struct message {
text *bounce; /* start of a bounced message */
text *binhex; /* start of a binhex message */
text *uuencode; /* start of a uuencoded message */
text *yenc; /* start of a yEnc message */
text *encoding; /* is the non MIME message encoded? */
} message;
@ -111,6 +115,7 @@ fileblob *messageToFileblob(message *m, const char *dir);
blob *messageToBlob(message *m);
text *messageToText(message *m);
const text *uuencodeBegin(const message *m);
const text *yEncBegin(const message *m);
const text *bounceBegin(const message *m);
const text *encodingLine(const message *m);
void messageClearMarkers(message *m);

Loading…
Cancel
Save