From 0fd32f8b9d707d807c236156de12118b0a695d69 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 14 May 2024 16:48:20 +0200 Subject: logging: Do not make assumptions in emit calls The Emit method of the Logger class, when called with a string as second argument, expects it to be a format string. It should be considered a programming error to pass a string variable as that argument without knowing for certain that it does not contain any format escape character ('{', '}'); instead, one should be conservative and use the blind format string "{}" as second argument and pass the unknown string variable as third argument. --- src/buildtool/execution_api/execution_service/operations_server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/buildtool/execution_api/execution_service/operations_server.cpp') diff --git a/src/buildtool/execution_api/execution_service/operations_server.cpp b/src/buildtool/execution_api/execution_service/operations_server.cpp index 13a8efd6..6e082bf4 100644 --- a/src/buildtool/execution_api/execution_service/operations_server.cpp +++ b/src/buildtool/execution_api/execution_service/operations_server.cpp @@ -24,7 +24,7 @@ auto OperarationsServiceImpl::GetOperation( ::google::longrunning::Operation* response) -> ::grpc::Status { auto const& hash = request->name(); if (auto error_msg = IsAHash(hash); error_msg) { - logger_.Emit(LogLevel::Debug, *error_msg); + logger_.Emit(LogLevel::Debug, "{}", *error_msg); return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, *error_msg}; } logger_.Emit(LogLevel::Trace, "GetOperation: {}", hash); @@ -33,7 +33,7 @@ auto OperarationsServiceImpl::GetOperation( if (!op) { auto const& str = fmt::format( "Executing action {} not found in internal cache.", hash); - logger_.Emit(LogLevel::Error, str); + logger_.Emit(LogLevel::Error, "{}", str); return ::grpc::Status{grpc::StatusCode::INTERNAL, str}; } response->CopyFrom(*op); -- cgit v1.2.3