Possible crash fixed.

git-svn: trunk@22
This commit is contained in:
Tomasz Kojm 2003-08-30 19:20:04 +00:00
parent 049a18b966
commit 0ae75a8d66
2 changed files with 93 additions and 47 deletions

View file

@ -44,6 +44,7 @@ blobCreate(void)
#ifdef CL_DEBUG #ifdef CL_DEBUG
blob *b = (blob *)cli_calloc(1, sizeof(blob)); blob *b = (blob *)cli_calloc(1, sizeof(blob));
b->magic = BLOB; b->magic = BLOB;
cli_dbgmsg("blobCreate\n");
return b; return b;
#else #else
return (blob *)cli_calloc(1, sizeof(blob)); return (blob *)cli_calloc(1, sizeof(blob));
@ -53,6 +54,12 @@ blobCreate(void)
void void
blobDestroy(blob *b) blobDestroy(blob *b)
{ {
#ifdef CL_DEBUG
cli_dbgmsg("blobDestroy %d\n", b->magic);
#else
cli_dbgmsg("blobDestroy\n");
#endif
assert(b != NULL); assert(b != NULL);
assert(b->magic == BLOB); assert(b->magic == BLOB);
@ -69,8 +76,13 @@ blobDestroy(blob *b)
void void
blobArrayDestroy(blob *blobList[], int n) blobArrayDestroy(blob *blobList[], int n)
{ {
while(--n >= 0) while(--n >= 0) {
blobDestroy(blobList[n]); cli_dbgmsg("blobArrayDestroy: %d\n", n);
if(blobList[n]) {
blobDestroy(blobList[n]);
blobList[n] = NULL;
}
}
} }
void void

View file

@ -61,12 +61,12 @@
typedef enum { FALSE = 0, TRUE = 1 } bool; typedef enum { FALSE = 0, TRUE = 1 } bool;
static const text *uuencodeBegin(const message *m);
static unsigned char *decodeLine(const message *m, const char *line, unsigned char *ptr); static unsigned char *decodeLine(const message *m, const char *line, unsigned char *ptr);
static unsigned char *decode(const char *in, unsigned char *out, unsigned char (*decoder)(char), bool isFast); static unsigned char *decode(const char *in, unsigned char *out, unsigned char (*decoder)(char), bool isFast);
static unsigned char hex(char c); static unsigned char hex(char c);
static unsigned char base64(char c); static unsigned char base64(char c);
static unsigned char uudecode(char c); static unsigned char uudecode(char c);
void logerr(const char *address, const char *format, ...);
static const char *messageGetArgument(const message *m, int arg); static const char *messageGetArgument(const message *m, int arg);
/* /*
@ -131,8 +131,11 @@ messageReset(message *m)
if(m->mimeDispositionType) if(m->mimeDispositionType)
free(m->mimeDispositionType); free(m->mimeDispositionType);
for(i = 0; i < m->numberOfArguments; i++) if(m->mimeArguments) {
free(m->mimeArguments[i]); for(i = 0; i < m->numberOfArguments; i++)
free(m->mimeArguments[i]);
free(m->mimeArguments);
}
if(m->body_first) if(m->body_first)
textDestroy(m->body_first); textDestroy(m->body_first);
@ -167,8 +170,15 @@ messageSetMimeType(message *mess, const char *type)
if(mess->mimeType == NOMIME) { if(mess->mimeType == NOMIME) {
if(strncasecmp(type, "x-", 2) == 0) if(strncasecmp(type, "x-", 2) == 0)
mess->mimeType = MEXTENSION; mess->mimeType = MEXTENSION;
else else {
fprintf(stderr, "Unknown MIME type `%s'", type); /*
* Based on a suggestion by James Stevens
* <James@kyzo.com>
* Force scanning of strange messages
*/
cli_warnmsg("Unknown MIME type: `%s' - set to Application\n", type);
mess->mimeType = APPLICATION;
}
} }
} }
@ -510,7 +520,7 @@ messageToBlob(const message *m)
{ {
blob *b; blob *b;
const text *t_line = NULL; const text *t_line = NULL;
const char *line, *filename; const char *filename;
assert(m != NULL); assert(m != NULL);
@ -527,24 +537,7 @@ messageToBlob(const message *m)
char *strptr; char *strptr;
#endif #endif
/* t_line = uuencodeBegin(m);
* Scan to find the UUENCODED message (if any)
*
* Fix based on an idea by Magnus Jonsson
* <Magnus.Jonsson@umdac.umu.se>, to allow for blank
* lines before the begin. Should not happen, but some
* e-mail clients are rather broken...
*/
for(t_line = messageGetBody(m); t_line; t_line = t_line->t_next) {
line = t_line->t_text;
if((strncasecmp(line, "begin ", 6) == 0) &&
(isdigit(line[6])) &&
(isdigit(line[7])) &&
(isdigit(line[8])) &&
(line[9] == ' '))
break;
}
if(t_line == NULL) { if(t_line == NULL) {
/*cli_warnmsg("UUENCODED attachment is missing begin statement\n");*/ /*cli_warnmsg("UUENCODED attachment is missing begin statement\n");*/
@ -552,7 +545,7 @@ messageToBlob(const message *m)
return NULL; return NULL;
} }
copy = strdup(line); copy = strdup(t_line->t_text);
(void)strtok_r(copy, " ", &strptr); (void)strtok_r(copy, " ", &strptr);
(void)strtok_r(NULL, " ", &strptr); (void)strtok_r(NULL, " ", &strptr);
filename = strtok_r(NULL, "\r\n", &strptr); filename = strtok_r(NULL, "\r\n", &strptr);
@ -611,8 +604,7 @@ messageToBlob(const message *m)
do { do {
unsigned char data[1024]; unsigned char data[1024];
unsigned char *uptr; unsigned char *uptr;
const char *line = t_line->t_text;
line = t_line->t_text;
if(messageGetEncoding(m) == UUENCODE) if(messageGetEncoding(m) == UUENCODE)
if(strcasecmp(line, "end") == 0) if(strcasecmp(line, "end") == 0)
@ -664,28 +656,44 @@ messageToText(const message *m)
sprintf(last->t_text, "%s\n", line); sprintf(last->t_text, "%s\n", line);
} }
else for(t_line = messageGetBody(m); t_line; t_line = t_line->t_next) { else {
unsigned char data[1024]; if(messageGetEncoding(m) == UUENCODE) {
unsigned char *uptr; t_line = uuencodeBegin(m);
const char *line = t_line->t_text;
uptr = decodeLine(m, line, data); if(t_line == NULL) {
/*cli_warnmsg("UUENCODED attachment is missing begin statement\n");*/
return NULL;
}
t_line = t_line->t_next;
} else
t_line = messageGetBody(m);
if(uptr == NULL) for(; t_line; t_line = t_line->t_next) {
break; unsigned char data[1024];
unsigned char *uptr;
const char *line = t_line->t_text;
assert(uptr <= &data[sizeof(data)]); if(messageGetEncoding(m) == UUENCODE)
if(strcasecmp(line, "end") == 0)
break;
uptr = decodeLine(m, line, data);
if(first == NULL) if(uptr == NULL)
first = last = cli_malloc(sizeof(text)); break;
else {
last->t_next = cli_malloc(sizeof(text)); assert(uptr <= &data[sizeof(data)]);
last = last->t_next;
if(first == NULL)
first = last = cli_malloc(sizeof(text));
else {
last->t_next = cli_malloc(sizeof(text));
last = last->t_next;
}
assert(last != NULL);
last->t_text = strdup((char *)data);
assert(last->t_text != NULL);
} }
assert(last != NULL);
last->t_text = strdup((char *)data);
assert(last->t_text != NULL);
} }
if(last) if(last)
@ -694,9 +702,35 @@ messageToText(const message *m)
return first; return first;
} }
static const text *
uuencodeBegin(const message *m)
{
const text *t_line;
/*
* Scan to find the UUENCODED message (if any)
*
* Fix based on an idea by Magnus Jonsson
* <Magnus.Jonsson@umdac.umu.se>, to allow for blank
* lines before the begin. Should not happen, but some
* e-mail clients are rather broken...
*/
for(t_line = messageGetBody(m); t_line; t_line = t_line->t_next) {
const char *line = t_line->t_text;
if((strncasecmp(line, "begin ", 6) == 0) &&
(isdigit(line[6])) &&
(isdigit(line[7])) &&
(isdigit(line[8])) &&
(line[9] == ' '))
return t_line;
}
return NULL;
}
/* /*
* Decode a line and add it to a buffer, return the end of the buffer * Decode a line and add it to a buffer, return the end of the buffer
* to help appending callers * to help appending callers. There is no new line at the end of "line"
*/ */
static unsigned char * static unsigned char *
decodeLine(const message *m, const char *line, unsigned char *ptr) decodeLine(const message *m, const char *line, unsigned char *ptr)