From c6770763e612f214422952998b6a8e3c3b3d97d1 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 14 Dec 2011 01:43:31 +0000 Subject: [PATCH] http://llvm.org/bugs/show_bug.cgi?id=11560 lldb::SBTarget::FindFirstType crashes when passed None Add null checks to several functions. Plus add test scenario for passing None to SBTarget.FindFirstType(None) and friends. llvm-svn: 146540 --- lldb/source/API/SBTarget.cpp | 8 ++++---- lldb/source/Core/Module.cpp | 3 +++ lldb/test/python_api/default-constructor/sb_target.py | 1 + lldb/test/python_api/type/TestTypeList.py | 4 ++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index e8a39a93aa04..179cb9372de4 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -1188,7 +1188,7 @@ SBTarget::FindFunctions (const char *name, { if (!append) sc_list.Clear(); - if (m_opaque_sp) + if (name && m_opaque_sp) { const bool symbols_ok = true; return m_opaque_sp->GetImages().FindFunctions (ConstString(name), @@ -1203,7 +1203,7 @@ SBTarget::FindFunctions (const char *name, lldb::SBType SBTarget::FindFirstType (const char* type) { - if (m_opaque_sp) + if (type && m_opaque_sp) { size_t count = m_opaque_sp->GetImages().GetSize(); for (size_t idx = 0; idx < count; idx++) @@ -1223,7 +1223,7 @@ SBTarget::FindTypes (const char* type) SBTypeList retval; - if (m_opaque_sp) + if (type && m_opaque_sp) { ModuleList& images = m_opaque_sp->GetImages(); ConstString name_const(type); @@ -1251,7 +1251,7 @@ SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) { SBValueList sb_value_list; - if (m_opaque_sp) + if (name && m_opaque_sp) { VariableList variable_list; const bool append = true; diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index cfe61efcfe6f..ad5e3407d51a 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -506,6 +506,9 @@ Module::FindTypes_Impl (const SymbolContext& sc, const ConstString &name, const static const char* StripTypeName(const char* name_cstr) { + // Protect against null c string. + if (!name_cstr) + return name_cstr; const char* skip_namespace = strstr(name_cstr, "::"); const char* template_arg_char = strchr(name_cstr, '<'); while (skip_namespace != NULL) diff --git a/lldb/test/python_api/default-constructor/sb_target.py b/lldb/test/python_api/default-constructor/sb_target.py index 3b0a70cb8b85..bff6f8f7edf0 100644 --- a/lldb/test/python_api/default-constructor/sb_target.py +++ b/lldb/test/python_api/default-constructor/sb_target.py @@ -24,6 +24,7 @@ def fuzz_obj(obj): obj.FindFunctions("the_func", 0xff, True, contextlist) obj.FindFirstType("dont_care") obj.FindTypes("dont_care") + obj.FindFirstType(None) obj.GetSourceManager() obj.FindGlobalVariables("my_global_var", 1) address = obj.ResolveLoadAddress(0xffff) diff --git a/lldb/test/python_api/type/TestTypeList.py b/lldb/test/python_api/type/TestTypeList.py index c2dda911428d..6f7e81145d62 100644 --- a/lldb/test/python_api/type/TestTypeList.py +++ b/lldb/test/python_api/type/TestTypeList.py @@ -69,6 +69,10 @@ class TypeAndTypeListTestCase(TestBase): self.assertTrue(type) self.DebugSBType(type) + # Pass an empty string. LLDB should not crash. :-) + fuzz_types = target.FindTypes(None) + fuzz_type = target.FindFirstType(None) + # Now use the SBTarget.FindFirstType() API to find 'Task'. task_type = target.FindFirstType('Task') self.assertTrue(task_type)