Skip to content

net/textproto: missing/incorrect arg in error string. #43408

Description

@morrowc

What version of Go are you using (go version)?

go version go1.15.6 linux/amd64

Does this issue reproduce with the latest release?

yes, when I ingest/read an SMTP delivered message with net/mail (as a NewMessage())

What operating system and processor architecture are you using (go env)?

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/morrowc/.cache/go-build"
GOENV="/home/morrowc/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/morrowc/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/morrowc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib//pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmes

What did you do?

Read an email message from a named-pipe (file would also work), parse into a NewMessage():

   // n == 'server'
   //  pipe here is a pd, err := os.OpenFile(pn, os.O_RDONLY, os.ModeNamedPipe)
   msg, err := mail.ReadMessage(n.pipe)

What did you expect to see?

'not an error' ...

What did you see instead?

E1228 21:55:30.838373   21601 nmsg_smtp.go:94] failed to ReadMailMessage, error: malformed MIME header: missing colon: %!q(MISSING)������Ƽ������˲�����������롢��ۻ�������ۼ�У��ASK��У�����ʼ�У������

example message is available at:
http://docs.as701.net/tmp/golang_issue_example_msg.txt

The process to jam patches in here is .. more than I want to do on vacation, but:

$ diff --git a/src/net/textproto/reader.go b/src/net/textproto/reader.go
index 5c3084f8a7..f39b9237d4 100644
--- a/src/net/textproto/reader.go
+++ b/src/net/textproto/reader.go
@@ -556,7 +556,7 @@ func noValidation(_ []byte) error { return nil }
 // contain a colon.
 func mustHaveFieldNameColon(line []byte) error {
        if bytes.IndexByte(line, ':') < 0 {
-               return ProtocolError(fmt.Sprintf("malformed MIME header: missing colon: %q", line))
+               return ProtocolError(fmt.Sprintf("malformed MIME header: missing colon: %q", string(line)))
        }
        return nil
 }

that would almost certainly fix the error's missing / wrong type of arg.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions