From da9759ca307d8a24c0bedce3a771d3cb79b96cbd Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 22 Jun 2017 09:35:10 -0400 Subject: [PATCH] cmd/bundle: fix nil dereference panic In the loader API, (*Config).Import, like go/build, accepts relative paths such as ".", but (*Program).Package requires the exact path of a loaded package. So, to find the package identified by "." we must look at the set of packages actually loaded, which in this scenario is guaranteed to be a singleton. (This is a definite weakness of the loader API. In the more general case where two or more packages are imported, it's tricky to correlate the calls to Import with the package(s) each call actually loads.) Fixes golang/go#20751 Change-Id: I925e969c9b4f4d6b6344c16f156b47857436d70a Reviewed-on: https://go-review.googlesource.com/46414 Reviewed-by: Josh Bleecher Snyder --- cmd/bundle/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/bundle/main.go b/cmd/bundle/main.go index 02bd8357..6d25aa86 100644 --- a/cmd/bundle/main.go +++ b/cmd/bundle/main.go @@ -200,7 +200,9 @@ func bundle(src, dst, dstpkg, prefix string) ([]byte, error) { return nil, err } - info := lprog.Package(src) + // Because there was a single Import call and Load succeeded, + // InitialPackages is guaranteed to hold the sole requested package. + info := lprog.InitialPackages()[0] if prefix == "" { pkgName := info.Files[0].Name.Name prefix = pkgName + "_"