From 9059861edf2ba68c5ea356918a0347323c9f0d2b Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 21 Dec 2019 06:35:51 -0500 Subject: Null-terminate read literals No wonder there was garbage... Silly mistake! --- imbox.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/imbox.c b/imbox.c index 9f46983..1712615 100644 --- a/imbox.c +++ b/imbox.c @@ -65,8 +65,6 @@ static void mboxrd(const char *headers, const char *body) { ); printf("%s", headers); - // FIXME: There seems to sometimes be some garbage data at the end of the - // headers? static regex_t quoteRegex; compile("eRegex, "^>*From "); @@ -161,12 +159,13 @@ static char *readLiteral(FILE *imap, const char *line) { size_t size = strtoul(prefix + 1, NULL, 10); if (!size) errx(EX_PROTOCOL, "invalid literal size"); - char *literal = malloc(size); + char *literal = malloc(size + 1); if (!literal) err(EX_OSERR, "malloc"); size_t count = fread(literal, size, 1, imap); if (!count) errx(EX_PROTOCOL, "could not read literal"); + literal[size] = '\0'; return literal; } -- cgit 1.4.1