[Lldb-commits] [lldb] f3a7d79 - [lldb/DWARF] Fix evaluator crash when accessing empty stack.

Med Ismail Bennani via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 31 08:45:47 PDT 2020


Author: Med Ismail Bennani
Date: 2020-03-31T17:44:57+02:00
New Revision: f3a7d790df3357d52c10ec5ef48606944bcf5c6c

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

LOG: [lldb/DWARF] Fix evaluator crash when accessing empty stack.

This patch fixes a crash that happens on the DWARF expression evaluator
when trying to access the top of the stack while it's empty.

rdar://60512489

Differential Revision: https://reviews.llvm.org/D77108

Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>

Added: 
    

Modified: 
    lldb/source/Expression/DWARFExpression.cpp
    lldb/unittests/Expression/DWARFExpressionTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
index 7f12d06450c6..04fbfccd0c2e 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -2318,6 +2318,12 @@ bool DWARFExpression::Evaluate(
     // rather is a constant value.  The value from the top of the stack is the
     // value to be used.  This is the actual object value and not the location.
     case DW_OP_stack_value:
+      if (stack.empty()) {
+        if (error_ptr)
+          error_ptr->SetErrorString(
+              "Expression stack needs at least 1 item for DW_OP_stack_value.");
+        return false;
+      }
       stack.back().SetValueType(Value::eValueTypeScalar);
       break;
 

diff  --git a/lldb/unittests/Expression/DWARFExpressionTest.cpp b/lldb/unittests/Expression/DWARFExpressionTest.cpp
index 64755a9066de..4c4281983078 100644
--- a/lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ b/lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -234,6 +234,10 @@ TEST(DWARFExpression, DW_OP_convert) {
       llvm::Failed());
 }
 
+TEST(DWARFExpression, DW_OP_stack_value) {
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_stack_value}), llvm::Failed());
+}
+
 TEST(DWARFExpression, DW_OP_piece) {
   EXPECT_THAT_EXPECTED(Evaluate({DW_OP_const2u, 0x11, 0x22, DW_OP_piece, 2,
                                  DW_OP_const2u, 0x33, 0x44, DW_OP_piece, 2}),


        


More information about the lldb-commits mailing list