1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2026-10-29 15:02:30 +00:00

dkim: Messages without a blank line should have an empty body

Today, if a message does not have a blank line (which separates headers
and body), we also include all lines except the first as the body (even
the ones parsed as headers). This is incorrect.

This patch fixes the code so that in those messages, all the lines are
headers, and the body is empty.

Note that since SMTP messages have to end with a new line, that final
line will act as the separator if there is no body. So this bug only
impacts signing/verification of files on disk via chasquid-util.
This commit is contained in:
Alberto Bertogli
2026-10-09 11:07:20 +01:00
parent ce236e91bc
commit 49030cb9c8
2 changed files with 15 additions and 4 deletions
+10 -2
View File
@@ -37,7 +37,9 @@ func parseMessage(message string) (headers, string, error) {
// Group the lines of each header: the first line, followed by its
// continuation lines (if any).
groups := [][]string{}
eoh := 0
// End of headers. If there's no blank line, all the lines are headers.
eoh := len(lines)
for i, line := range lines {
if line == "" {
eoh = i
@@ -67,7 +69,13 @@ func parseMessage(message string) (headers, string, error) {
headers = append(headers, h)
}
return headers, strings.Join(lines[eoh+1:], "\r\n"), nil
// The body is everything after the blank line (if there is one).
body := ""
if eoh < len(lines) {
body = strings.Join(lines[eoh+1:], "\r\n")
}
return headers, body, nil
}
// Parse a header, given its lines (the first one, followed by the
+5 -2
View File
@@ -116,8 +116,8 @@ func TestParseMessageWithErrors(t *testing.T) {
func TestParseMessageWithoutBlankLine(t *testing.T) {
// If there's no blank line, all the lines are headers, including the
// continuation lines of the last one.
hs, _, err := parseMessage("From: a@b\r\nTo: c@d\r\n e@f")
// continuation lines of the last one, and the body is empty.
hs, body, err := parseMessage("From: a@b\r\nTo: c@d\r\n e@f")
if err != nil {
t.Fatalf("parseMessage error: %v", err)
}
@@ -128,6 +128,9 @@ func TestParseMessageWithoutBlankLine(t *testing.T) {
if diff := cmp.Diff(want, hs); diff != "" {
t.Errorf("parseMessage headers mismatch (-want +got):\n%s", diff)
}
if body != "" {
t.Errorf("parseMessage body: wanted empty, got %q", body)
}
}
func TestParseMessageManyContinuations(t *testing.T) {