golang/go

net/mail: parses invalid address

dvyukov opened this issue · 7 comments

The following program fails with the panic:

package main

import (
    "fmt"
    "net/mail"
)

func main() {
    data := "\"\"@0"
    addr, err := mail.ParseAddress(data)
    if err != nil {
        return
    }
    _, err = mail.ParseAddress(addr.String())
    if err != nil {
        fmt.Printf("failed to parse addr: %q -> %q\n", data, addr)
        panic(err)
    }
}
failed to parse addr: "\"\"@0" -> "<@0>"
panic: mail: invalid string

I guess that address should have not been parsed in the first place.

go version devel +514014c Thu Jun 18 15:54:35 2015 +0200 linux/amd64

This is probably the same issue:

    data := "\"0:\"@0"

but worth a separate test.

One more:

    data := "\"\t0\"@0"

What is wrong with data := "\"0:\"@0" ?

It does not parse successfully in the second mail.ParseAddress call. Either first mail.ParseAddress or String corrupt it somehow, or it should not be parsed the first time as well.

I recently did a patchrequest to fix that round trip issue #10768: daaa450 (will be included in Go 1.5 afaik)

First and third example should indeed fail to parse, which doesn't happen. If I find some time I can look into it, doesn't seem hard to solve.

CL https://golang.org/cl/12905 mentions this issue.

I uploaded a patch request for this issue...
https://golang.org/cl/12905