Fix crash if x-yencode is mistakenly guessed

git-svn: trunk@1072
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent 6c507c4034
commit 4b187745e4
  1. 5
      clamav-devel/ChangeLog
  2. 19
      clamav-devel/libclamav/mbox.c
  3. 20
      clamav-devel/libclamav/message.c

@ -1,3 +1,8 @@
Mon Nov 8 10:29:02 GMT 2004 (njh)
----------------------------------
* libclamav/message.c: Fix crash if the guessed encoder is incorrectly
thought to be yEnc
Mon Nov 8 10:28:41 CET 2004 (tk)
---------------------------------
* clamd: force SHUTDOWN on memory errors from libclamav

@ -17,6 +17,9 @@
*
* Change History:
* $Log: mbox.c,v $
* Revision 1.168 2004/11/08 10:26:22 nigelhorne
* Fix crash if x-yencode is mistakenly guessed
*
* Revision 1.167 2004/11/07 16:59:42 nigelhorne
* Tidy
*
@ -489,7 +492,7 @@
* Compilable under SCO; removed duplicate code with message.c
*
*/
static char const rcsid[] = "$Id: mbox.c,v 1.167 2004/11/07 16:59:42 nigelhorne Exp $";
static char const rcsid[] = "$Id: mbox.c,v 1.168 2004/11/08 10:26:22 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -784,7 +787,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
int retcode, i;
message *m, *body;
FILE *fd;
char buffer[LINE_LENGTH];
char buffer[LINE_LENGTH + 1];
#ifdef HAVE_BACKTRACE
void (*segv)(int);
#endif
@ -798,7 +801,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
close(i);
return CL_EOPEN;
}
if(fgets(buffer, sizeof(buffer), fd) == NULL) {
if(fgets(buffer, sizeof(buffer) - 1, fd) == NULL) {
/* empty message */
fclose(fd);
return CL_CLEAN;
@ -879,7 +882,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
lastLineWasEmpty = (bool)(buffer[0] == '\0');
if(messageAddStr(m, buffer) < 0)
break;
} while(fgets(buffer, sizeof(buffer), fd) != NULL);
} while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL);
cli_dbgmsg("Deal with email number %d\n", messagenumber);
} else {
@ -892,16 +895,18 @@ cli_mbox(const char *dir, int desc, unsigned int options)
* CommuniGate Pro format: ignore headers until
* blank line
*/
while((fgets(buffer, sizeof(buffer), fd) != NULL) &&
while((fgets(buffer, sizeof(buffer) - 1, fd) != NULL) &&
(strchr("\r\n", buffer[0]) == NULL))
;
/*
* Ignore any blank lines at the top of the message
*/
while(strchr("\r\n", buffer[0]) &&
(fgets(buffer, sizeof(buffer), fd) != NULL))
(fgets(buffer, sizeof(buffer) - 1, fd) != NULL))
;
buffer[LINE_LENGTH] = '\0';
/*
* FIXME: files full of new lines and nothing else are
* handled ungracefully...
@ -917,7 +922,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
(void)cli_chomp(buffer);
if(messageAddStr(m, buffer) < 0)
break;
} while(fgets(buffer, sizeof(buffer), fd) != NULL);
} while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL);
}
fclose(fd);

@ -17,6 +17,9 @@
*
* Change History:
* $Log: message.c,v $
* Revision 1.110 2004/11/08 10:26:22 nigelhorne
* Fix crash if x-yencode is mistakenly guessed
*
* Revision 1.109 2004/11/07 16:39:00 nigelhorne
* Handle para 4 of RFC2231
*
@ -324,7 +327,7 @@
* uuencodebegin() no longer static
*
*/
static char const rcsid[] = "$Id: message.c,v 1.109 2004/11/07 16:39:00 nigelhorne Exp $";
static char const rcsid[] = "$Id: message.c,v 1.110 2004/11/08 10:26:22 nigelhorne Exp $";
#if HAVE_CONFIG_H
#include "clamav-config.h"
@ -699,7 +702,7 @@ messageAddArgument(message *m, const char *arg)
m->mimeArguments = ptr;
}
m->mimeArguments[offset] = rfc2231(arg);
arg = m->mimeArguments[offset] = rfc2231(arg);
/*
* This is terribly broken from an RFC point of view but is useful
@ -1257,6 +1260,8 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
if(ret == NULL)
return NULL;
cli_dbgmsg("messageExport: numberOfEncTypes == %d\n", m->numberOfEncTypes);
if((t_line = binhexBegin(m)) != NULL) {
unsigned char byte;
unsigned long len, l, newlen = 0L;
@ -1587,7 +1592,7 @@ 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))) {
} else if(((enctype == YENCODE) && yEncBegin(m)) || ((i == 0) && yEncBegin(m))) {
/*
* TODO: handle multipart yEnc encoded files
*/
@ -2544,9 +2549,8 @@ messageDedup(message *m)
static char *
rfc2231(const char *in)
{
char *out;
char *ptr;
char *ret;
const char *ptr;
char *ret, *out;
enum { LANGUAGE, CHARSET, CONTENTS } field = LANGUAGE;
ptr = strstr(in, "*=");
@ -2604,11 +2608,11 @@ rfc2231(const char *in)
}
if(field != CONTENTS) {
cli_warnmsg("Invalid RFC2231 header: '%s'\n", in);
free(ret);
cli_warnmsg("Invalid RFC2231 header: '%s'\n", in);
return strdup("");
}
*out = '\0';
cli_dbgmsg("rfc2231 returns '%s'\n", ret);

Loading…
Cancel
Save