Fix not handling invalid RCPT TO addresses.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 18 Dec 2016 07:45:12 +0000 (02:45 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 18 Dec 2016 07:45:12 +0000 (02:45 -0500)
pop3/conn_test.go
smtp/conn.go
smtp/conn_test.go

index 061deffa01d19a9f8714186bbf412d8cfe977339..4671bcabbb38b72dc9db084a5975ced971034883 100644 (file)
@@ -11,6 +11,8 @@ import (
        "runtime"
        "strings"
        "testing"
+
+       "github.com/uber-go/zap"
 )
 
 func _fl(depth int) string {
@@ -59,7 +61,7 @@ func runServer(t *testing.T, po PostOffice) net.Listener {
                        if err != nil {
                                return
                        }
-                       go AcceptConnection(conn, po)
+                       go AcceptConnection(conn, po, zap.New(zap.NullEncoder()))
                }
        }()
        return l
index 33bca297041d1a3a13956280760438df53cdc9f1..8b4f1247ea7d6fec6d5b583174f990b1ca2f3b10 100644 (file)
@@ -210,7 +210,7 @@ func (conn *connection) doMAIL() {
 
        var err error
        conn.mailFrom, err = mail.ParseAddress(mailFrom)
-       if err != nil {
+       if err != nil || conn.mailFrom == nil {
                conn.reply(ReplyBadSyntax)
                return
        }
@@ -236,6 +236,7 @@ func (conn *connection) doRCPT() {
        address, err := mail.ParseAddress(rcptTo)
        if err != nil {
                conn.reply(ReplyBadSyntax)
+               return
        }
 
        if reply := conn.server.VerifyAddress(*address); reply != ReplyOK {
index cd75299dda4a0d9c44a7d64abbd8fb4b4449c3a3..0fa5bb6acc21347507cbea54f2c7b541e329588b 100644 (file)
@@ -10,6 +10,8 @@ import (
        "strings"
        "testing"
        "time"
+
+       "github.com/uber-go/zap"
 )
 
 func _fl(depth int) string {
@@ -46,7 +48,7 @@ func runServer(t *testing.T, server Server) net.Listener {
                        if err != nil {
                                return
                        }
-                       go AcceptConnection(conn, server)
+                       go AcceptConnection(conn, server, zap.New(zap.NullEncoder()))
                }
        }()
 
@@ -166,6 +168,22 @@ func TestVerifyAddress(t *testing.T) {
        })
 }
 
+func TestBadAddress(t *testing.T) {
+       l := runServer(t, &testServer{})
+       defer l.Close()
+
+       conn := createClient(t, l.Addr())
+       readCodeLine(t, conn, 220)
+
+       runTableTest(t, conn, []requestResponse{
+               {"EHLO test", 0, func(t testing.TB, conn *textproto.Conn) { conn.ReadResponse(250) }},
+               {"MAIL FROM:<sender>", 501, nil},
+               {"MAIL FROM:<sender@foo.com>", 250, nil},
+               {"RCPT TO:<banned.net>", 501, nil},
+               {"QUIT", 221, nil},
+       })
+}
+
 func TestCaseSensitivty(t *testing.T) {
        s := &testServer{}
        l := runServer(t, s)
@@ -229,7 +247,7 @@ func TestGetReceivedInfo(t *testing.T) {
 
                conn.ehlo = test.params.ehlo
                conn.esmtp = test.params.esmtp
-               conn.tls = test.params.tls
+               //conn.tls = test.params.tls
 
                envelope := Envelope{
                        RcptTo:   []mail.Address{{"", test.params.address}},