Skip to content

Commit

Permalink
cmd/go/internal/load: prevent set ImportPathError when the err is alr…
Browse files Browse the repository at this point in the history
…eady *module.InvalidPathError

1. The call of setError is unnecessary bacause setError do nothing when
p.Error is not nil.
2. The call of ImportErrorf may panic in this situation
(double quotes appear in the import path).

Fixes golang#49137
  • Loading branch information
SilverRainZ committed Dec 10, 2021
1 parent 8ff254e commit 1985479
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1844,12 +1844,18 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
if other := foldPath[fold]; other == "" {
foldPath[fold] = p.ImportPath
} else if other != p.ImportPath {
setError(ImportErrorf(p.ImportPath, "case-insensitive import collision: %q and %q", p.ImportPath, other))
var invalidPathErr *module.InvalidPathError
if !errors.As(err, &invalidPathErr) {
setError(ImportErrorf(p.ImportPath, "case-insensitive import collision: %q and %q", p.ImportPath, other))
}
return
}

if !SafeArg(p.ImportPath) {
setError(ImportErrorf(p.ImportPath, "invalid import path %q", p.ImportPath))
var invalidPathErr *module.InvalidPathError
if !errors.As(err, &invalidPathErr) {
setError(ImportErrorf(p.ImportPath, "invalid import path %q", p.ImportPath))
}
return
}

Expand Down

0 comments on commit 1985479

Please sign in to comment.