Merge pull request #46065 from corhere/libn/defuse-datastore-key-latent-race

libnetwork/datastore: prevent data races in Key()
This commit is contained in:
Sebastiaan van Stijn 2023-07-24 19:53:24 +02:00 committed by GitHub
commit 7ced56b356
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -149,9 +149,14 @@ func (cfg *ScopeCfg) IsValid() bool {
// Key provides convenient method to create a Key
func Key(key ...string) string {
keychain := append(rootChain, key...)
str := strings.Join(keychain, "/")
return str + "/"
var b strings.Builder
for _, parts := range [][]string{rootChain, key} {
for _, part := range parts {
b.WriteString(part)
b.WriteString("/")
}
}
return b.String()
}
// ParseKey provides convenient method to unpack the key to complement the Key function