Commit 6719d889 authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go/internal/get: avoid panic in metaImportsForPrefix if web.Get fails

Fixes #34049

Change-Id: I817b83ee2d0ca6d01ec64998f14bc4f32e365d66
Reviewed-on: https://go-review.googlesource.com/c/go/+/193259
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDmitri Shuralyov <dmitshur@golang.org>
parent d9a3d902
...@@ -904,7 +904,7 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu ...@@ -904,7 +904,7 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu
} }
resp, err := web.Get(security, url) resp, err := web.Get(security, url)
if err != nil { 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 body := resp.Body
defer body.Close() defer body.Close()
...@@ -913,7 +913,7 @@ func metaImportsForPrefix(importPrefix string, mod ModuleMode, security web.Secu ...@@ -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)}) return setCache(fetchResult{url: url, err: fmt.Errorf("parsing %s: %v", resp.URL, err)})
} }
if len(imports) == 0 { 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}) return setCache(fetchResult{url: url, imports: imports, err: err})
}) })
......
# golang.org/issue/29591: 'go get' was following plain-HTTP redirects even without -insecure. # 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 [!net] skip
[!exec:git] skip [!exec:git] skip
env GO111MODULE=on env GO111MODULE=off
env GOPROXY=direct
env GOSUMDB=off
! go get -d vcs-test.golang.org/insecure/go/insecure ! go get -d vcs-test.golang.org/insecure/go/insecure
stderr 'redirected .* to insecure URL' stderr 'redirected .* to insecure URL'
......
# 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
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