flashmob / go-guerrilla

Mini SMTP server written in golang
MIT License
2.79k stars 366 forks source link

Header detection issue #139

Closed iwex closed 5 years ago

iwex commented 5 years ago

I have some problem with headers. I testes it with swaks, it sends valid headers, but Guerrilla can't parse headers and gives me error:

DEBU[0001] Client sent: DATA
DEBU[0001] Writing response to client: 54 Enter message, ending with '.' on a line by itself
ERRO[0001] parse headers error error=EOF

I tested it with swaks -f me@example.org -t test@example.com --server 127.0.0.1:2525

flashmob commented 5 years ago

Hi, thanks for the report. Do you know what is the full input that is fed to the DATA command? Please paste a sample here.

On Fri., 15 Mar. 2019, 02:12 Serhii Chaplia, notifications@github.com wrote:

I have some problem with headers. I testes it with swaks, it sends valid headers, but Guerrilla can't parse headers and gives me error:

DEBU[0001] Client sent: DATA DEBU[0001] Writing response to client: 54 Enter message, ending with '.' on a line by itself ERRO[0001] parse headers error error=EOF

I tested it with swaks -f me@example.org -t test@example.com --server 127.0.0.1:2525

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/139, or mute the thread https://github.com/notifications/unsubscribe-auth/AAnmP8hGnQfnZGbT_KoJo46q4IOnz33Qks5vWmbxgaJpZM4b0Zl8 .

iwex commented 5 years ago

@flashmob sure

=== Trying localhost:2525...
=== Connected to localhost.
<-  220 iwex-pc SMTP Guerrilla(unknown) #1 (1) 2019-03-15T15:26:53+02:00
 -> EHLO iwex-pc
<-  250-iwex-pc Hello
<-  250-SIZE 10485760
<-  250-PIPELINING
<-  250-ENHANCEDSTATUSCODES
<-  250 HELP
 -> MAIL FROM:<me@example.org>
<-  250 2.1.0 OK
 -> RCPT TO:<test@example.com>
<-  250 2.1.5 OK
 -> DATA
<-  354 Enter message, ending with '.' on a line by itself
 -> Date: Fri, 15 Mar 2019 15:26:53 +0200
 -> To: test@example.com
 -> From: me@example.org
 -> Subject: test Fri, 15 Mar 2019 15:26:53 +0200
 -> Message-Id: <20190315152653.027193@iwex-pc>
 -> X-Mailer: swaks v20181104.0 jetmore.org/john/code/swaks/
 -> 
 -> This is a test mailing
 -> 
 -> 
 -> .
<-  250 2.0.0 OK: queued as a04ac137fdce82ed46362ca1daf0399d
 -> QUIT
<-  221 2.0.0 Bye
codestation commented 5 years ago

I have the same problem. The error comes from here.

From the ReadMIMEHeader documentation it expects a blank line at the end but the header slice doesn't include it.

IMO the fix can be like this.

header := buf[0:headerEnd+2]

It won't be out of bounds because the Index call before it made sure that those two bytes exists.