From 9b9fbbe5bd85576874c912e0f46c7173b3700bbb Mon Sep 17 00:00:00 2001 From: Luke Zhang Date: Thu, 20 Mar 2025 14:54:54 -0700 Subject: [PATCH] fix: buffer overrun in the gRPC sample project Building the sample on Windows, the gRPC sample server/client app fails to function correctly. The propagated trace context is corrupted, containing garbage characters after the trace parent string. The string buffer from gRPC cannot be safely treated as a null-terminated C-string. To ensure safe copying, we must use its length property instead. --- examples/grpc/tracer_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/grpc/tracer_common.h b/examples/grpc/tracer_common.h index fd931767ad..cb9940a715 100644 --- a/examples/grpc/tracer_common.h +++ b/examples/grpc/tracer_common.h @@ -59,7 +59,7 @@ class GrpcServerCarrier : public opentelemetry::context::propagation::TextMapCar auto it = context_->client_metadata().find({key.data(), key.size()}); if (it != context_->client_metadata().end()) { - return it->second.data(); + return opentelemetry::nostd::string_view(it->second.data(), it->second.size()); } return ""; }