diff --git a/mail.c b/mail.c index a6d11fc..e055461 100644 --- a/mail.c +++ b/mail.c @@ -345,7 +345,7 @@ int readmail(struct queue *queue, int nodot, int recp_from_header) { struct parse_state parse_state; - char line[1000]; /* by RFC2822 */ + char line[1000+1]; /* by RFC2822 (and allow fgets to append '\0') */ size_t linelen; size_t error; int had_headers = 0; @@ -379,12 +379,14 @@ readmail(struct queue *queue, int nodot, int recp_from_header) " from %s (uid %d) (envelope-from %s)", username, useruid, queue->sender); linelen = strlen(line); - if (linelen == 0 || line[linelen - 1] != '\n') { + if (linelen == 0 || line[linelen - 2] != '\r' || line[linelen - 1] != '\n' ) { /* - * This line did not end with a newline character. + * This line did not end with a CRLF, cludge it. * If we fix it, it better be the last line of * the file. + * XXX: overwriting valid input is probably inadequate */ + line[linelen-1] = '\r'; line[linelen] = '\n'; line[linelen + 1] = 0; had_last_line = 1;