Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
morrowc opened this issue Dec 28, 2020 · 3 comments
Open

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

morrowc opened this issue Dec 28, 2020 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@morrowc
Copy link

morrowc commented Dec 28, 2020

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.

@robpike
Copy link
Contributor

robpike commented Dec 28, 2020

Whatever the problem may be, that is not the fix, as the %q Printf verb formats a byte slice as a string already. Converting it to string does nothing except possibly add an unnecessary allocation. See https://play.golang.org/p/t3jcl9vKfOo

@morrowc
Copy link
Author

morrowc commented Dec 29, 2020 via email

@toothrot
Copy link
Contributor

toothrot commented Jan 5, 2021

Also /cc @bradfitz @rsc per https://dev.golang.org/owners

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 5, 2021
@toothrot toothrot added this to the Backlog milestone Jan 5, 2021
@seankhliao seankhliao changed the title net/textproto/message.go: Missing/incorrect arg in error string. net/textproto: missing/incorrect arg in error string. Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants