Commit f53a9868 authored by Russ Cox's avatar Russ Cox

cmd/go: fix detection of unexpected files in downloaded zips

A bug in the old code was indirectly causing a confusing print,
but CL 131635 fixed the print instead of the surrounding code.
Fix the surrounding code, restore the old print, and test that the
error is actually reported (it was being ignored in a direct go get
but displaying in go build).

Change-Id: I03c21380fce481060c443b0cc820f3617497fdd9
Reviewed-on: https://go-review.googlesource.com/c/149317Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent 69010963
...@@ -119,11 +119,11 @@ func downloadZip(mod module.Version, target string) error { ...@@ -119,11 +119,11 @@ func downloadZip(mod module.Version, target string) error {
if err != nil { if err != nil {
return err return err
} }
prefix := mod.Path + "@" + mod.Version prefix := mod.Path + "@" + mod.Version + "/"
for _, f := range z.File { for _, f := range z.File {
if !strings.HasPrefix(f.Name, prefix) { if !strings.HasPrefix(f.Name, prefix) {
z.Close() z.Close()
return fmt.Errorf("zip for %s has unexpected file %s", prefix, f.Name) return fmt.Errorf("zip for %s has unexpected file %s", prefix[:len(prefix)-1], f.Name)
} }
} }
z.Close() z.Close()
......
...@@ -534,9 +534,11 @@ func runGet(cmd *base.Command, args []string) { ...@@ -534,9 +534,11 @@ func runGet(cmd *base.Command, args []string) {
// module root. // module root.
continue continue
} }
base.Errorf("%s", p.Error)
} }
todo = append(todo, p) todo = append(todo, p)
} }
base.ExitIfErrors()
// If -d was specified, we're done after the download: no build. // If -d was specified, we're done after the download: no build.
// (The load.PackagesAndErrors is what did the download // (The load.PackagesAndErrors is what did the download
......
...@@ -197,7 +197,13 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) { ...@@ -197,7 +197,13 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(f.Name, ".") { if strings.HasPrefix(f.Name, ".") {
continue continue
} }
zf, err := z.Create(path + "@" + vers + "/" + f.Name) var zipName string
if strings.HasPrefix(f.Name, "/") {
zipName = f.Name[1:]
} else {
zipName = path + "@" + vers + "/" + f.Name
}
zf, err := z.Create(zipName)
if err != nil { if err != nil {
return cached{nil, err} return cached{nil, err}
} }
......
rsc.io/badzip v1.0.0
written by hand
-- .mod --
module rsc.io/badzip
-- .info --
{"Version":"v1.0.0"}
-- x.go --
package x
-- /rsc.io/badzip@v1.0.0.txt --
This file should not be here.
# Zip files with unexpected file names inside should be rejected.
env GO111MODULE=on
! go get -d rsc.io/badzip
stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt'
! go build rsc.io/badzip
stderr 'zip for rsc.io/badzip@v1.0.0 has unexpected file rsc.io/badzip@v1.0.0.txt'
-- go.mod --
module m
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment