[Lldb-commits] [lldb] ad0f7d3 - [lldb] Fix Scripted ProcessLaunchInfo Argument nullptr deref
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 10 08:43:49 PST 2021
Author: Med Ismail Bennani
Date: 2021-11-10T16:43:19Z
New Revision: ad0f7d3d4a0c7ceaa5878494b2ad673287ef6a76
URL: https://github.com/llvm/llvm-project/commit/ad0f7d3d4a0c7ceaa5878494b2ad673287ef6a76
DIFF: https://github.com/llvm/llvm-project/commit/ad0f7d3d4a0c7ceaa5878494b2ad673287ef6a76.diff
LOG: [lldb] Fix Scripted ProcessLaunchInfo Argument nullptr deref
This patch adds a new `StructuredData::Dictionary` constructor that
takes a `StructuredData::ObjectSP` as an argument. This is used to pass
the opaque_ptr from the `SBStructuredData` used to initialize a
ScriptedProecss, to the `ProcessLaunchInfo` class.
This also updates `SBLaunchInfo::SetScriptedProcessDictionary` to
reflect the formentionned changes which solves the nullptr deref.
Differential Revision: https://reviews.llvm.org/D112107
Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>
Added:
Modified:
lldb/include/lldb/Core/StructuredDataImpl.h
lldb/include/lldb/Utility/StructuredData.h
lldb/source/API/SBLaunchInfo.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/StructuredDataImpl.h b/lldb/include/lldb/Core/StructuredDataImpl.h
index 929ce21fb2f92..d6f64451e5c22 100644
--- a/lldb/include/lldb/Core/StructuredDataImpl.h
+++ b/lldb/include/lldb/Core/StructuredDataImpl.h
@@ -152,6 +152,8 @@ class StructuredDataImpl {
return (::snprintf(dst, dst_len, "%s", result.data()));
}
+ StructuredData::ObjectSP GetObjectSP() const { return m_data_sp; }
+
private:
lldb::StructuredDataPluginWP m_plugin_wp;
StructuredData::ObjectSP m_data_sp;
diff --git a/lldb/include/lldb/Utility/StructuredData.h b/lldb/include/lldb/Utility/StructuredData.h
index 4d03af18e527b..c1d136db1c2ef 100644
--- a/lldb/include/lldb/Utility/StructuredData.h
+++ b/lldb/include/lldb/Utility/StructuredData.h
@@ -353,6 +353,17 @@ class StructuredData {
public:
Dictionary() : Object(lldb::eStructuredDataTypeDictionary), m_dict() {}
+ Dictionary(ObjectSP obj_sp)
+ : Object(lldb::eStructuredDataTypeDictionary), m_dict() {
+ if (!obj_sp || obj_sp->GetType() != lldb::eStructuredDataTypeDictionary) {
+ SetType(lldb::eStructuredDataTypeInvalid);
+ return;
+ }
+
+ Dictionary *dict = obj_sp->GetAsDictionary();
+ m_dict = dict->m_dict;
+ }
+
~Dictionary() override = default;
size_t GetSize() const { return m_dict.size(); }
diff --git a/lldb/source/API/SBLaunchInfo.cpp b/lldb/source/API/SBLaunchInfo.cpp
index 70cd1c6ecf744..0735e62a16cfd 100644
--- a/lldb/source/API/SBLaunchInfo.cpp
+++ b/lldb/source/API/SBLaunchInfo.cpp
@@ -380,16 +380,18 @@ lldb::SBStructuredData SBLaunchInfo::GetScriptedProcessDictionary() const {
void SBLaunchInfo::SetScriptedProcessDictionary(lldb::SBStructuredData dict) {
LLDB_RECORD_METHOD(void, SBLaunchInfo, SetScriptedProcessDictionary,
(lldb::SBStructuredData), dict);
+ if (!dict.IsValid() || !dict.m_impl_up)
+ return;
- SBStream stream;
- SBError error = dict.GetAsJSON(stream);
+ StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();
- if (error.Fail())
+ if (!obj_sp)
return;
- StructuredData::DictionarySP dict_sp;
- llvm::json::OStream s(stream.ref().AsRawOstream());
- dict_sp->Serialize(s);
+ StructuredData::DictionarySP dict_sp =
+ std::make_shared<StructuredData::Dictionary>(obj_sp);
+ if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
+ return;
m_opaque_sp->SetScriptedProcessDictionarySP(dict_sp);
}
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 63c68c2a20236..23659bdb8a47a 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -106,7 +106,7 @@ ScriptedProcess::ScriptedProcess(
StructuredData::GenericSP object_sp = GetInterface().CreatePluginObject(
m_scripted_process_info.GetClassName().c_str(), exe_ctx,
- m_scripted_process_info.GetDictionarySP());
+ m_scripted_process_info.GetArgsSP());
if (!object_sp || !object_sp->IsValid()) {
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index fd4a94b9b6adb..3f8d53908339b 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -25,17 +25,15 @@ class ScriptedProcess : public Process {
public:
ScriptedProcessInfo(const ProcessLaunchInfo &launch_info) {
m_class_name = launch_info.GetScriptedProcessClassName();
- m_dictionary_sp = launch_info.GetScriptedProcessDictionarySP();
+ m_args_sp = launch_info.GetScriptedProcessDictionarySP();
}
std::string GetClassName() const { return m_class_name; }
- StructuredData::DictionarySP GetDictionarySP() const {
- return m_dictionary_sp;
- }
+ StructuredData::DictionarySP GetArgsSP() const { return m_args_sp; }
private:
std::string m_class_name;
- StructuredData::DictionarySP m_dictionary_sp;
+ StructuredData::DictionarySP m_args_sp;
};
public:
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index de1203300e4b4..dbe9e5019ff84 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -55,7 +55,7 @@ ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error)
StructuredData::GenericSP object_sp =
scripted_thread_interface->CreatePluginObject(
class_name->c_str(), exe_ctx,
- process.m_scripted_process_info.GetDictionarySP());
+ process.m_scripted_process_info.GetArgsSP());
if (!object_sp || !object_sp->IsValid()) {
error.SetErrorString("Failed to create valid script object");
return;
More information about the lldb-commits
mailing list