1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:04:43 -07:00

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 <josharian@gmail.com>
This commit is contained in:
Alan Donovan 2017-06-22 09:35:10 -04:00
parent 1ab5277e83
commit da9759ca30

View File

@ -200,7 +200,9 @@ func bundle(src, dst, dstpkg, prefix string) ([]byte, error) {
return nil, err 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 == "" { if prefix == "" {
pkgName := info.Files[0].Name.Name pkgName := info.Files[0].Name.Name
prefix = pkgName + "_" prefix = pkgName + "_"