]> Cypherpunks repositories - gostls13.git/commitdiff
net/smtp: ignore HELO error in QUIT
authorIan Lance Taylor <iant@golang.org>
Fri, 25 Oct 2024 00:20:42 +0000 (17:20 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 25 Oct 2024 04:52:06 +0000 (04:52 +0000)
Fixes #70011

Change-Id: I9d8b3ffbd66561eee0efffd54038960acd5fcf64
Reviewed-on: https://go-review.googlesource.com/c/go/+/622476
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/net/smtp/smtp.go
src/net/smtp/smtp_test.go

index d750a2854cbf90bbfd62047a82dcd1caaf678965..522d80e4eb57cf3ee9a4e04f82b852ff607cd6d8 100644 (file)
@@ -413,9 +413,7 @@ func (c *Client) Noop() error {
 
 // Quit sends the QUIT command and closes the connection to the server.
 func (c *Client) Quit() error {
-       if err := c.hello(); err != nil {
-               return err
-       }
+       c.hello() // ignore error; we're quitting anyhow
        _, _, err := c.cmd(221, "QUIT")
        if err != nil {
                return err
index c91c99b1f5311193c39360da6beda953269a5878..389eda9ad54b993f28601e1574b5910a89fbe334 100644 (file)
@@ -288,6 +288,37 @@ Goodbye.
 QUIT
 `
 
+func TestHELOFailed(t *testing.T) {
+       serverLines := `502 EH?
+502 EH?
+221 OK
+`
+       clientLines := `EHLO localhost
+HELO localhost
+QUIT
+`
+
+       server := strings.Join(strings.Split(serverLines, "\n"), "\r\n")
+       client := strings.Join(strings.Split(clientLines, "\n"), "\r\n")
+       var cmdbuf strings.Builder
+       bcmdbuf := bufio.NewWriter(&cmdbuf)
+       var fake faker
+       fake.ReadWriter = bufio.NewReadWriter(bufio.NewReader(strings.NewReader(server)), bcmdbuf)
+       c := &Client{Text: textproto.NewConn(fake), localName: "localhost"}
+
+       if err := c.Hello("localhost"); err == nil {
+               t.Fatal("expected EHLO to fail")
+       }
+       if err := c.Quit(); err != nil {
+               t.Errorf("QUIT failed: %s", err)
+       }
+       bcmdbuf.Flush()
+       actual := cmdbuf.String()
+       if client != actual {
+               t.Errorf("Got:\n%s\nWant:\n%s", actual, client)
+       }
+}
+
 func TestExtensions(t *testing.T) {
        fake := func(server string) (c *Client, bcmdbuf *bufio.Writer, cmdbuf *strings.Builder) {
                server = strings.Join(strings.Split(server, "\n"), "\r\n")