Skip to content

Commit

Permalink
cmd/go/internal/get: avoid panic in metaImportsForPrefix if web.Get f…
Browse files Browse the repository at this point in the history
…ails

Fixes #34049

Change-Id: I817b83ee2d0ca6d01ec64998f14bc4f32e365d66
Reviewed-on: https://go-review.googlesource.com/c/go/+/193259
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
Bryan C. Mills committed Sep 4, 2019
1 parent d9a3d90 commit 6719d88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/cmd/go/internal/get/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
}
resp, err := web.Get(security, url)
if err != nil {
return setCache(fetchResult{url: url, err: fmt.Errorf("fetch %s: %v", resp.URL, err)})
return setCache(fetchResult{url: url, err: fmt.Errorf("fetching %s: %v", importPrefix, err)})
}
body := resp.Body
defer body.Close()
Expand All @@ -913,7 +913,7 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
return setCache(fetchResult{url: url, err: fmt.Errorf("parsing %s: %v", resp.URL, err)})
}
if len(imports) == 0 {
err = fmt.Errorf("fetch %s: no go-import meta tag", url)
err = fmt.Errorf("fetching %s: no go-import meta tag found in %s", importPrefix, resp.URL)
}
return setCache(fetchResult{url: url, imports: imports, err: err})
})
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/go/testdata/script/get_insecure_redirect.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# golang.org/issue/29591: 'go get' was following plain-HTTP redirects even without -insecure.
# golang.org/issue/34049: 'go get' would panic in case of an insecure redirect in GOPATH mode

[!net] skip
[!exec:git] skip

env GO111MODULE=on
env GOPROXY=direct
env GOSUMDB=off
env GO111MODULE=off

! go get -d vcs-test.golang.org/insecure/go/insecure
stderr 'redirected .* to insecure URL'
Expand Down
13 changes: 13 additions & 0 deletions src/cmd/go/testdata/script/mod_get_insecure_redirect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# golang.org/issue/29591: 'go get' was following plain-HTTP redirects even without -insecure.

[!net] skip
[!exec:git] skip

env GO111MODULE=on
env GOPROXY=direct
env GOSUMDB=off

! go get -d vcs-test.golang.org/insecure/go/insecure
stderr 'redirected .* to insecure URL'

go get -d -insecure vcs-test.golang.org/insecure/go/insecure

0 comments on commit 6719d88

Please sign in to comment.