Skip to content

Commit

Permalink
metadata: copy slices in FromContext() functions (#5267)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Mar 22, 2022
1 parent 9d08896 commit 2fccb82
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions metadata/metadata.go
Expand Up @@ -188,7 +188,9 @@ func FromIncomingContext(ctx context.Context) (MD, bool) {
// map, and there's no guarantee that the MD attached to the context is
// created using our helper functions.
key := strings.ToLower(k)
out[key] = v
s := make([]string, len(v))
copy(s, v)
out[key] = s
}
return out, true
}
Expand Down Expand Up @@ -226,7 +228,9 @@ func FromOutgoingContext(ctx context.Context) (MD, bool) {
// map, and there's no guarantee that the MD attached to the context is
// created using our helper functions.
key := strings.ToLower(k)
out[key] = v
s := make([]string, len(v))
copy(s, v)
out[key] = s
}
for _, added := range raw.added {
if len(added)%2 == 1 {
Expand Down

0 comments on commit 2fccb82

Please sign in to comment.