Skip to content

Commit

Permalink
modfetch: prevent duplicate hashes in go.sum
Browse files Browse the repository at this point in the history
To write go.sum, each module and then each hash is looped through.
The hashes are kept in a slice and there is no check to ensure
that hashes were not added or already exist in the file. This
uniques the hashes of each module before writting to prevent
duplicates.

Fixes: #28456
  • Loading branch information
Josh Powers committed Jun 8, 2022
1 parent 346698e commit a76c0f8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cmd/go/internal/modfetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"cmd/go/internal/lockedfile"
"cmd/go/internal/par"
"cmd/go/internal/robustio"
"cmd/go/internal/str"
"cmd/go/internal/trace"

"golang.org/x/mod/module"
Expand Down Expand Up @@ -832,6 +833,7 @@ Outer:
for _, m := range mods {
list := goSum.m[m]
sort.Strings(list)
str.Uniq(&list)
for _, h := range list {
st := goSum.status[modSum{m, h}]
if (!st.dirty || (st.used && keep[m])) && !sumInWorkspaceModulesLocked(m) {
Expand Down

0 comments on commit a76c0f8

Please sign in to comment.