From ffe1ba7a5dc229de2e009c8712d0c7f8c82748c9 Mon Sep 17 00:00:00 2001 From: Denis Protivensky Date: Tue, 17 Oct 2023 13:53:11 +0300 Subject: [PATCH] Fix use-after-free in wsrep::log --- include/wsrep/logger.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/wsrep/logger.hpp b/include/wsrep/logger.hpp index a15873c..4a9c46b 100644 --- a/include/wsrep/logger.hpp +++ b/include/wsrep/logger.hpp @@ -86,7 +86,11 @@ namespace wsrep { if (logger_fn_) { - logger_fn_(level_, prefix_, oss_.str().c_str()); + // Prolong the lifetime of the string so it doesn't get + // destroyed right after evaluating c_str() and before + // completing the logger function call. + const std::string& tmp = oss_.str(); + logger_fn_(level_, prefix_, tmp.c_str()); } else {