Index: contrib/dma/dma.h =================================================================== --- contrib/dma/dma.h (revision 333683) +++ contrib/dma/dma.h (working copy) @@ -60,6 +60,7 @@ #endif #define SMTP_PORT 25 /* Default SMTP port */ #define CON_TIMEOUT (5*60) /* Connection timeout per RFC5321 */ +#define MAX_LINE_RFC822 1000 /* Max line length per RFC822 */ #define STARTTLS 0x002 /* StartTLS support */ #define SECURETRANS 0x004 /* SSL/TLS in general */ Index: contrib/dma/local.c =================================================================== --- contrib/dma/local.c (revision 333683) +++ contrib/dma/local.c (working copy) @@ -126,7 +126,7 @@ deliver_local(struct qitem *it) { char fn[PATH_MAX+1]; - char line[1000]; + char line[MAX_LINE_RFC822]; const char *sender; const char *newline = "\n"; size_t linelen; @@ -205,9 +205,9 @@ goto wrerror; while (!feof(it->mailf)) { - if (fgets(line, sizeof(line), it->mailf) == NULL) + if (fgets(line, sizeof(line)+1, it->mailf) == NULL) break; - linelen = strlen(line); + linelen = strnlen(line, sizeof(line)); if (linelen == 0 || line[linelen - 1] != '\n') { syslog(LOG_CRIT, "local delivery failed: corrupted queue file"); snprintf(errmsg, sizeof(errmsg), "corrupted queue file"); Index: contrib/dma/mail.c =================================================================== --- contrib/dma/mail.c (revision 333683) +++ contrib/dma/mail.c (working copy) @@ -41,8 +41,6 @@ #include "dma.h" -#define MAX_LINE_RFC822 1000 - void bounce(struct qitem *it, const char *reason) { @@ -351,7 +349,7 @@ while (linelen > 0) { len = linelen; if (linelen > MAX_LINE_RFC822) { - len = MAX_LINE_RFC822 - 10; + len = MAX_LINE_RFC822 - 1; } if (fwrite(line, len, 1, queue->mailf) != 1) @@ -363,7 +361,7 @@ if (fwrite("\n", 1, 1, queue->mailf) != 1) return (-1); - line += MAX_LINE_RFC822 - 10; + line += MAX_LINE_RFC822 - 1; linelen = strlen(line); } return (0); Index: contrib/dma/net.c =================================================================== --- contrib/dma/net.c (revision 333683) +++ contrib/dma/net.c (working copy) @@ -352,7 +352,7 @@ deliver_to_host(struct qitem *it, struct mx_hostentry *host) { struct authuser *a; - char line[1000]; + char line[MAX_LINE_RFC822]; size_t linelen; int fd, error = 0, do_auth = 0, res = 0; @@ -450,9 +450,9 @@ error = 0; while (!feof(it->mailf)) { - if (fgets(line, sizeof(line), it->mailf) == NULL) + if (fgets(line, sizeof(line)+1, it->mailf) == NULL) break; - linelen = strlen(line); + linelen = strnlen(line, sizeof(line)); if (linelen == 0 || line[linelen - 1] != '\n') { syslog(LOG_CRIT, "remote delivery failed: corrupted queue file"); snprintf(errmsg, sizeof(errmsg), "corrupted queue file");