Browse Source

Hotfix: Short mail from would crash to panic (#63)

Fixed: Short "mail from" would cause panic
Philipp Resch 8 years ago
parent
commit
8b0cec45c7
2 changed files with 63 additions and 1 deletions
  1. 3 1
      server.go
  2. 60 0
      tests/guerrilla_test.go

+ 3 - 1
server.go

@@ -361,7 +361,9 @@ func (server *server) handleClient(client *client) {
 				// Fix for issue #53 - MAIL FROM may only be <> if it is a bounce
 				mail := input[10:]
 				from := &envelope.EmailAddress{}
-				if mail[0:2] != "<>" {
+
+				if !(strings.Index(mail, "<>") == 0) &&
+					!(strings.Index(mail, " <>") == 0) {
 					// Not Bounce, extract mail.
 					from, err = extractEmail(mail)
 				}

+ 60 - 0
tests/guerrilla_test.go

@@ -612,6 +612,66 @@ func TestMailFromCmd(t *testing.T) {
 				t.Error("Server did not respond with", expected, ", it said:"+response)
 			}
 
+			// No mail from content
+			response, err = Command(conn, bufin, "MAIL FROM:")
+			if err != nil {
+				t.Error("command failed", err.Error())
+			}
+			expected = "501 5.5.4 Invalid address"
+			if strings.Index(response, expected) != 0 {
+				t.Error("Server did not respond with", expected, ", it said:"+response)
+			}
+
+			// Reset
+			response, err = Command(conn, bufin, "RSET")
+			if err != nil {
+				t.Error("command failed", err.Error())
+			}
+			expected = "250 2.1.0 OK"
+			if strings.Index(response, expected) != 0 {
+				t.Error("Server did not respond with", expected, ", it said:"+response)
+			}
+
+			// Short mail from content
+			response, err = Command(conn, bufin, "MAIL FROM:<")
+			if err != nil {
+				t.Error("command failed", err.Error())
+			}
+			expected = "501 5.5.4 Invalid address"
+			if strings.Index(response, expected) != 0 {
+				t.Error("Server did not respond with", expected, ", it said:"+response)
+			}
+
+			// Reset
+			response, err = Command(conn, bufin, "RSET")
+			if err != nil {
+				t.Error("command failed", err.Error())
+			}
+			expected = "250 2.1.0 OK"
+			if strings.Index(response, expected) != 0 {
+				t.Error("Server did not respond with", expected, ", it said:"+response)
+			}
+
+			// Short mail from content 2
+			response, err = Command(conn, bufin, "MAIL FROM:x")
+			if err != nil {
+				t.Error("command failed", err.Error())
+			}
+			expected = "501 5.5.4 Invalid address"
+			if strings.Index(response, expected) != 0 {
+				t.Error("Server did not respond with", expected, ", it said:"+response)
+			}
+
+			// Reset
+			response, err = Command(conn, bufin, "RSET")
+			if err != nil {
+				t.Error("command failed", err.Error())
+			}
+			expected = "250 2.1.0 OK"
+			if strings.Index(response, expected) != 0 {
+				t.Error("Server did not respond with", expected, ", it said:"+response)
+			}
+
 			// What?
 			response, err = Command(conn, bufin, "MAIL FROM:<<>>")
 			if err != nil {