diff --git a/src/config.h b/src/config.h index 8b219e6..927f64d 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-master-branch" -#define BUILD 860 +#define BUILD 861 #define HOSTID "mailarchiver" diff --git a/src/parser.c b/src/parser.c index 9e88ffa..43cdffc 100644 --- a/src/parser.c +++ b/src/parser.c @@ -109,7 +109,7 @@ clearhash(state->journal_recipient); trimBuffer(state->b_subject); - fixupEncodedHeaderLine(state->b_subject); + fixupEncodedHeaderLine(state->b_subject, MAXBUFSIZE); if(sdata->internal_sender == 0) sdata->direction = DIRECTION_INCOMING; @@ -265,7 +265,7 @@ if(take_into_pieces == 1){ state->fd = open(state->attachments[state->n_attachments].internalname, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR); - fixupEncodedHeaderLine(state->attachments[state->n_attachments].filename); + fixupEncodedHeaderLine(state->attachments[state->n_attachments].filename, TINYBUFSIZE); p = get_attachment_extractor_by_filename(state->attachments[state->n_attachments].filename); @@ -428,7 +428,7 @@ } if(state->is_1st_header == 1){ - fixupEncodedHeaderLine(buf); + fixupEncodedHeaderLine(buf, MAXBUFSIZE); } diff --git a/src/parser.h b/src/parser.h index 62a30ae..436631e 100644 --- a/src/parser.h +++ b/src/parser.h @@ -17,7 +17,7 @@ unsigned long parse_date_header(char *s, struct __config *cfg); int isHexNumber(char *p); int extract_boundary(char *p, struct _state *state); -void fixupEncodedHeaderLine(char *buf); +void fixupEncodedHeaderLine(char *buf, int buflen); void fixupSoftBreakInQuotedPritableLine(char *buf, struct _state *state); void fixupBase64EncodedLine(char *buf, struct _state *state); void markHTML(char *buf, struct _state *state); diff --git a/src/parser_utils.c b/src/parser_utils.c index 0d43eec..cc9ac1b 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -315,7 +315,7 @@ } -void fixupEncodedHeaderLine(char *buf){ +void fixupEncodedHeaderLine(char *buf, int buflen){ char *sb, *sq, *p, *q, *r, *s, *e, *start, *end; char v[SMALLBUFSIZE], puf[MAXBUFSIZE], encoding[SMALLBUFSIZE], tmpbuf[2*SMALLBUFSIZE]; iconv_t cd; @@ -323,6 +323,7 @@ char *inbuf, *outbuf; int need_encoding; + if(buflen < 5) return; memset(puf, 0, sizeof(puf)); @@ -412,7 +413,7 @@ } while(q); - snprintf(buf, MAXBUFSIZE-1, "%s", puf); + snprintf(buf, buflen-1, "%s", puf); } @@ -740,7 +741,7 @@ int extractNameFromHeaderLine(char *s, char *name, char *resultbuf){ int rc=0; - char buf[TINYBUFSIZE], *p, *q; + char buf[SMALLBUFSIZE], puf[SMALLBUFSIZE], *p, *q; snprintf(buf, sizeof(buf)-1, "%s", s); @@ -760,7 +761,13 @@ p++; } } - snprintf(resultbuf, TINYBUFSIZE-1, "%s", p); + + snprintf(puf, sizeof(puf)-1, "%s", p); + + fixupEncodedHeaderLine(puf, sizeof(puf)); + + snprintf(resultbuf, TINYBUFSIZE-1, "%s", puf); + rc = 1; } } diff --git a/test/parser.c b/test/parser.c index 6ca6ed3..0a073d1 100644 --- a/test/parser.c +++ b/test/parser.c @@ -164,6 +164,9 @@ snprintf(datestr, sizeof(datestr)-2, "Date: 03 Jun 06 05:59:00 +0100"); ts = parse_date_header(datestr, &cfg); printf("%s => %ld\n", datestr, ts); + snprintf(datestr, sizeof(datestr)-2, "Date: 03-Feb-2014 18:00:00"); + ts = parse_date_header(datestr, &cfg); printf("%s => %ld\n", datestr, ts); + return count; }