From ecd849ed5696fac0ac6a6eb8f7ec9d1034cb7a40 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 3 Oct 2019 07:59:26 +0000 Subject: Fix a use-after-free in GDBRemoteCommunicationServerLLGS Although it's called "GetString", StreamString::GetString actually returns a StringRef. Creating a json object with a StringRef does not make a copy, which means the StringRef will be dangling as soon as the underlying stream is destroyed. Add a .str() to force the json object to hold a copy of the string. This fixes nearly every test on linux. llvm-svn: 373572 --- .../Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp') diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 4e719143da5..36fb1781364 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -462,7 +462,8 @@ GetRegistersAsJSON(NativeThreadProtocol &thread) { WriteRegisterValueInHexFixedWidth(stream, reg_ctx, *reg_info_p, ®_value, lldb::eByteOrderBig); - register_object.try_emplace(llvm::to_string(reg_num), stream.GetString()); + register_object.try_emplace(llvm::to_string(reg_num), + stream.GetString().str()); } return register_object; -- cgit v1.2.3