fix: orm/*, store/*: fix non-determinism from map iteration (#12751)
Reported by informalsystems/gosec's map iteration pass, this change fixes non-determinism from iterating with a map, whose definition in the Go spec guarantees that the order of keys and values presented during iteration will be randomized. Fixes #12428 Fixes #12430 Fixes #12431
This commit is contained in:
+11
-1
@@ -15,7 +15,17 @@ import (
|
||||
)
|
||||
|
||||
func (m moduleDB) DefaultJSON(target ormjson.WriteTarget) error {
|
||||
for name, table := range m.tablesByName {
|
||||
tableNames := make([]protoreflect.FullName, 0, len(m.tablesByName))
|
||||
for name := range m.tablesByName {
|
||||
tableNames = append(tableNames, name)
|
||||
}
|
||||
sort.Slice(tableNames, func(i, j int) bool {
|
||||
ti, tj := tableNames[i], tableNames[j]
|
||||
return ti.Name() < tj.Name()
|
||||
})
|
||||
|
||||
for _, name := range tableNames {
|
||||
table := m.tablesByName[name]
|
||||
w, err := target.OpenWriter(name)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user