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
This commit is contained in:
Pavel Labath 2019-10-03 07:59:26 +00:00
parent c0292744da
commit ecd849ed56
1 changed files with 2 additions and 1 deletions

View File

@ -462,7 +462,8 @@ GetRegistersAsJSON(NativeThreadProtocol &thread) {
WriteRegisterValueInHexFixedWidth(stream, reg_ctx, *reg_info_p,
&reg_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;