llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Daniil Kovalev (kovdan01)

<details>
<summary>Changes</summary>

If `LLVM_TARGETS_TO_BUILD` does not contain `X86` and we try to run an x86 
binary in lldb, we get a `nullptr` dereference in `LLVMDisasmInstruction(...)`. 
We try to call `getDisAsm()` method on a `LLVMDisasmContext *DC` which is null. 
The pointer is passed from 
`x86AssemblyInspectionEngine::instruction_length(...)` and is originally 
`m_disasm_context` member of `x86AssemblyInspectionEngine`. This should be 
filled by `LLVMCreateDisasm(...)` in the class constructor, but not having X86 
target enabled in llvm makes `TargetRegistry::lookupTarget(...)` call return 
`nullptr`, which results in `m_disasm_context` initialized with `nullptr` as 
well.

This patch adds if statements against `m_disasm_context` in 
`x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(...)` and 
`x86AssemblyInspectionEngine::FindFirstNonPrologueInstruction(...)` so 
subsequent calls to `x86AssemblyInspectionEngine::instruction_length(...)` do 
not cause a null pointer dereference.

---
Full diff: https://github.com/llvm/llvm-project/pull/82603.diff


1 Files Affected:

- (modified) 
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp (+6) 


``````````diff
diff --git 
a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp 
b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
index 2032c5a68d054c..6bfaa54135a959 100644
--- a/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
+++ b/lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
@@ -909,6 +909,9 @@ bool 
x86AssemblyInspectionEngine::GetNonCallSiteUnwindPlanFromAssembly(
   if (!m_register_map_initialized)
     return false;
 
+  if (m_disasm_context == nullptr)
+    return false;
+
   addr_t current_func_text_offset = 0;
   int current_sp_bytes_offset_from_fa = 0;
   bool is_aligned = false;
@@ -1570,6 +1573,9 @@ bool 
x86AssemblyInspectionEngine::FindFirstNonPrologueInstruction(
   if (!m_register_map_initialized)
     return false;
 
+  if (m_disasm_context == nullptr)
+    return false;
+
   while (offset < size) {
     int regno;
     int insn_len;

``````````

</details>


https://github.com/llvm/llvm-project/pull/82603
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to