diff --git a/contrib/dma/mail.c b/contrib/dma/mail.c --- a/contrib/dma/mail.c +++ b/contrib/dma/mail.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -418,8 +419,14 @@ * If we fix it, it better be the last line of * the file. */ - line[linelen] = '\n'; - line[linelen + 1] = 0; + if ((size_t)linelen + 1 > linecap) { + line = realloc(line, linelen + 2); + if (line == NULL) + errlogx(EX_SOFTWARE, "realloc"); + linecap = malloc_usable_size(line); + } + line[linelen++] = '\n'; + line[linelen] = 0; had_last_line = 1; } if (!had_first_line) {