From 04b9780b4e6f3e2618103f4b6abe7120410251ba Mon Sep 17 00:00:00 2001 From: Chuan Ren Date: Tue, 1 Dec 2020 15:27:04 -0800 Subject: [PATCH] Update external_account_credentials.cc --- .../external/external_account_credentials.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/lib/security/credentials/external/external_account_credentials.cc b/src/core/lib/security/credentials/external/external_account_credentials.cc index 599b718655f..5c05e2bf1eb 100644 --- a/src/core/lib/security/credentials/external/external_account_credentials.cc +++ b/src/core/lib/security/credentials/external/external_account_credentials.cc @@ -167,7 +167,16 @@ void ExternalAccountCredentials::OnExchangeTokenInternal(grpc_error* error) { } else { if (options_.service_account_impersonation_url.empty()) { metadata_req_->response = ctx_->response; - metadata_req_->response.body = gpr_strdup(ctx_->response.body); + metadata_req_->response.body = gpr_strdup( + std::string(ctx_->response.body, ctx_->response.body_length).c_str()); + metadata_req_->response.hdrs = static_cast( + gpr_malloc(sizeof(grpc_http_header) * ctx_->response.hdr_count)); + for (int i = 0; i < ctx_->response.hdr_count; i++) { + metadata_req_->response.hdrs[i].key = + gpr_strdup(ctx_->response.hdrs[i].key); + metadata_req_->response.hdrs[i].value = + gpr_strdup(ctx_->response.hdrs[i].value); + } FinishTokenFetch(GRPC_ERROR_NONE); } else { ImpersenateServiceAccount(); @@ -288,6 +297,14 @@ void ExternalAccountCredentials::OnImpersenateServiceAccountInternal( metadata_req_->response = ctx_->response; metadata_req_->response.body = gpr_strdup(body.c_str()); metadata_req_->response.body_length = body.length(); + metadata_req_->response.hdrs = static_cast( + gpr_malloc(sizeof(grpc_http_header) * ctx_->response.hdr_count)); + for (int i = 0; i < ctx_->response.hdr_count; i++) { + metadata_req_->response.hdrs[i].key = + gpr_strdup(ctx_->response.hdrs[i].key); + metadata_req_->response.hdrs[i].value = + gpr_strdup(ctx_->response.hdrs[i].value); + } FinishTokenFetch(GRPC_ERROR_NONE); }