From bebbba12196b01deca4e33631937fdfdf605b75c Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Thu, 12 Nov 2015 20:12:02 +0100 Subject: [PATCH] Only lines consisting of nothing but dashes are body separators This is how the documentation specifies it, see mh-mail(5). The old m_getfld(), however, was more relaxed and treated any header line that starts with a dash as the body separator. We are more strict here, because ``-foo: bar'' is a valid header line (according to RFC 2822), that should thus not be treated as the body separator, whereas a line ``------'' in the header could only be a format error if we don't take it as the body separator. --- sbr/m_getfld2.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index 6d96bdd..de38435 100644 --- a/sbr/m_getfld2.c +++ b/sbr/m_getfld2.c @@ -23,6 +23,7 @@ enum threestate { */ static enum threestate is_falted(FILE *); static size_t copyname(char *, char *); +static int is_separator(char *); /* @@ -48,7 +49,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) enum threestate falted; nchars = getline(&tmpline, &len, msg); - if (nchars == -1) { + if (nchars < 1) { if (feof(msg)) { return FILEEOF2; } else { @@ -80,7 +81,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) return FMTERR2; } - if (nchars > 0 && (*tmpline == '\n' || *tmpline == '-')) { + if (is_separator(tmpline)) { /* header/body separator found */ free(tmpline); return m_getfld2(BODY2, f, msg); @@ -215,3 +216,19 @@ copyname(char *dst, char *src) return strlen(dst); } + +static int +is_separator(char *line) +{ + /* + ** In MH, lines that are consists of dashes only are + ** separators as well ... not so in RFC 822. + */ + while (*line == '-') { + line++; + } + if (strcmp("\n", line)==0) { + return 1; + } + return 0; +} -- 1.7.10.4