[Lldb-commits] [lldb] e26eece - [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:28:28 PDT 2020


Author: Med Ismail Bennani
Date: 2020-03-31T17:28:15+02:00
New Revision: e26eece1e2e7d7e6fbadb1207afef9b6353b5330

URL: https://github.com/llvm/llvm-project/commit/e26eece1e2e7d7e6fbadb1207afef9b6353b5330
DIFF: https://github.com/llvm/llvm-project/commit/e26eece1e2e7d7e6fbadb1207afef9b6353b5330.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.

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