]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/archive: make error message contain printable characters only
authorCherry Zhang <cherryyz@google.com>
Fri, 30 Apr 2021 17:57:12 +0000 (13:57 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 30 Apr 2021 18:43:09 +0000 (18:43 +0000)
Use %q instead of %s to print unchecked bytes. Also strip the
"\x00" byte, as "go116ld" reads better than "\x00go116ld".

Change-Id: Id3d1f426ea91d53a55b928dac4a68e1333b80158
Reviewed-on: https://go-review.googlesource.com/c/go/+/315750
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/internal/archive/archive.go

index d1d51b285554743a20f687d7bea53b9981a326ed..da1f293243573e82e207cf8ec65390eb310f5ce6 100644 (file)
@@ -109,7 +109,7 @@ var (
 type ErrGoObjOtherVersion struct{ magic []byte }
 
 func (e ErrGoObjOtherVersion) Error() string {
-       return fmt.Sprintf("go object of a different version: %s", e.magic)
+       return fmt.Sprintf("go object of a different version: %q", e.magic)
 }
 
 // An objReader is an object file reader.
@@ -425,7 +425,7 @@ func (r *objReader) parseObject(o *GoObj, size int64) error {
        }
        if !bytes.Equal(p, []byte(goobj.Magic)) {
                if bytes.HasPrefix(p, []byte("\x00go1")) && bytes.HasSuffix(p, []byte("ld")) {
-                       return r.error(ErrGoObjOtherVersion{p})
+                       return r.error(ErrGoObjOtherVersion{p[1:]}) // strip the \x00 byte
                }
                return r.error(errCorruptObject)
        }