Author: Chelsea Cassanova
Date: 2022-06-08T18:10:41-04:00
New Revision: 0f02dd34f22650d8af0070e7ad21632525e33da8

URL: 
https://github.com/llvm/llvm-project/commit/0f02dd34f22650d8af0070e7ad21632525e33da8
DIFF: 
https://github.com/llvm/llvm-project/commit/0f02dd34f22650d8af0070e7ad21632525e33da8.diff

LOG: [lldb/Commands] Prevent crash due to reading memory from page zero.

Adds a check to ensure that a process exists before attempting to get
its ABI to prevent lldb from crashing due to trying to read from page zero.

Differential revision: https://reviews.llvm.org/D127016

Added: 
    lldb/test/Shell/Driver/TestPageZeroRead.test

Modified: 
    lldb/source/Commands/CommandObjectMemory.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index b7678add53995..ab54578898a17 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -592,7 +592,10 @@ class CommandObjectMemoryRead : public CommandObjectParsed 
{
       return false;
     }
 
-    ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
+    ABISP abi;
+    if (Process *proc = m_exe_ctx.GetProcessPtr())
+      abi = proc->GetABI();
+
     if (abi)
       addr = abi->FixDataAddress(addr);
 

diff  --git a/lldb/test/Shell/Driver/TestPageZeroRead.test 
b/lldb/test/Shell/Driver/TestPageZeroRead.test
new file mode 100644
index 0000000000000..474867f2cce7d
--- /dev/null
+++ b/lldb/test/Shell/Driver/TestPageZeroRead.test
@@ -0,0 +1,6 @@
+# REQUIRES: system-darwin
+# Ensure that the read from memory command doesn't try and read from page zero.
+# RUN: %clang_host %p/Inputs/hello.c -g -o a.out
+# RUN: %lldb -b a.out -o 'settings set 
interpreter.stop-command-source-on-error false' -s %s 2>&1 | FileCheck %s
+x 0
+# CHECK: error: error reading data from section __PAGEZERO


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to