Skip to content

Commit

Permalink
fix: check for empty header value and allow
Browse files Browse the repository at this point in the history
  • Loading branch information
sshort authored and emersion committed Apr 5, 2022
1 parent 8790ca6 commit b5c320e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ func TestMilterClient_UsualFlow(t *testing.T) {
hdr := textproto.Header{}
hdr.Add("From", "[email protected]")
hdr.Add("To", "[email protected]")
hdr.Add("x-empty-header", "")
act, err = session.Header(hdr)
assertAction(act, err, ActContinue)
if len(mm.Hdr) != 2 {
if len(mm.Hdr) != 3 {
t.Fatal("Unexpected header length:", len(mm.Hdr))
}
if val := mm.Hdr.Get("From"); val != "[email protected]" {
Expand All @@ -229,6 +230,9 @@ func TestMilterClient_UsualFlow(t *testing.T) {
if val := mm.Hdr.Get("To"); val != "[email protected]" {
t.Fatal("Wrong To header:", val)
}
if val := mm.Hdr.Get("x-empty-header"); val != "" {
t.Fatal("Wrong To header:", val)
}

modifyActs, act, err := session.BodyReadFrom(bytes.NewReader(bytes.Repeat([]byte{'A'}, 128000)))
assertAction(act, err, ActContinue)
Expand Down
4 changes: 4 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func (m *milterSession) Process(msg *Message) (Response, error) {
}
// add new header to headers map
headerData := decodeCStrings(msg.Data)
// headers with an empty body appear as `text\x00\x00`, decodeCStrings will drop the empty body
if len(headerData) == 1 {
headerData = append(headerData, "")
}
if len(headerData) == 2 {
m.headers.Add(headerData[0], headerData[1])
// call and return milter handler
Expand Down

0 comments on commit b5c320e

Please sign in to comment.