Skip to content

Commit 17436af

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modload: fix aliasing bug in (*mvsReqs).Required with -mod=vendor
(*mvsReqs).Required assumes that it is safe to mutate the slice returned by (*mvsReqs).required. In most cases, that was true, but in the case of -mod=vendor it resulted in unsynchronized (and potentially interfering) writes to the global vendorList. Fixes #30550 Change-Id: I99bcc2037e0182418b7dfda1002f8b540dbf3a1d Reviewed-on: https://go-review.googlesource.com/c/go/+/170598 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 94507d2 commit 17436af

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/cmd/go/internal/modload/load.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -976,27 +976,27 @@ func readVendorList() {
976976
}
977977

978978
func (r *mvsReqs) modFileToList(f *modfile.File) []module.Version {
979-
var list []module.Version
979+
list := make([]module.Version, 0, len(f.Require))
980980
for _, r := range f.Require {
981981
list = append(list, r.Mod)
982982
}
983983
return list
984984
}
985985

986+
// required returns a unique copy of the requirements of mod.
986987
func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) {
987988
if mod == Target {
988989
if modFile != nil && modFile.Go != nil {
989990
r.versions.LoadOrStore(mod, modFile.Go.Version)
990991
}
991-
var list []module.Version
992-
return append(list, r.buildList[1:]...), nil
992+
return append([]module.Version(nil), r.buildList[1:]...), nil
993993
}
994994

995995
if cfg.BuildMod == "vendor" {
996996
// For every module other than the target,
997997
// return the full list of modules from modules.txt.
998998
readVendorList()
999-
return vendorList, nil
999+
return append([]module.Version(nil), vendorList...), nil
10001000
}
10011001

10021002
if targetInGorootSrc {

0 commit comments

Comments
 (0)