From 2fccb822f142f24e18db9b720f2094d891a6a9f5 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Tue, 22 Mar 2022 14:15:22 -0700 Subject: [PATCH] metadata: copy slices in FromContext() functions (#5267) --- metadata/metadata.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/metadata/metadata.go b/metadata/metadata.go index 3604c7819fd..8e0f6abe89d 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -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 } @@ -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 {