]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.17] cmd/go/internal/modfetch: do not short-circuit canonical...
authorBryan C. Mills <bcmills@google.com>
Thu, 13 Jan 2022 20:38:14 +0000 (15:38 -0500)
committerCherry Mui <cherryyz@google.com>
Mon, 7 Feb 2022 18:43:23 +0000 (18:43 +0000)
commitfbcc30a2c9d076b27b4b411e2cec91ec13528081
tree392d5ea1fe3b1047ac23415dc4e95af53d4daa83
parentacb1ce53f9b1cf99269165517491fdb48b25ed59
[release-branch.go1.17] cmd/go/internal/modfetch: do not short-circuit canonical versions

Since at least CL 121857, the conversion logic in
(*modfetch).codeRepo.Stat has had a short-circuit to use the version
requested by the caller if it successfully resolves and is already
canonical.

However, we should not use that version if it refers to a branch
instead of a tag, because branches (unlike tags) usually do not refer
to a single, stable release: a branch named "v1.0.0" may be for the
development of the v1.0.0 release, or for the development of patches
based on v1.0.0, but only one commit (perhaps at the end of that
branch — but possibly not even written yet!) can be that specific
version.

We already have some logic to prefer tags that are semver-equivalent
to the version requested by the caller. That more general case
suffices for exact equality too — so we can eliminate the
special-case, fixing the bug and (happily!) also somewhat simplifying
the code.

Updates #35671
Fixes #50687
Fixes CVE-2022-23773

Change-Id: I2fd290190b8a99a580deec7e26d15659b58a50b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/378400
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit fa4d9b8e2bc2612960c80474fca83a4c85a974eb)
Reviewed-on: https://go-review.googlesource.com/c/go/+/382835
src/cmd/go/internal/modfetch/coderepo.go
src/cmd/go/internal/modfetch/coderepo_test.go
src/cmd/go/testdata/script/mod_invalid_version.txt