From ae8bc2f85984970c4ef47e6adbdff67c423ba034 Mon Sep 17 00:00:00 2001 From: Matthieu Volat Date: Thu, 12 Jan 2017 17:18:24 +0100 Subject: [PATCH] Sanitize the rest of dwarf operation regarding stack popping. In all those cases, the order of pop() was not an issue since the operations were commutatives, but those could give bad ideas for other cases. --- src/mc/DwarfExpression.cpp | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/mc/DwarfExpression.cpp b/src/mc/DwarfExpression.cpp index 03298eb6ba..86043a0bf9 100644 --- a/src/mc/DwarfExpression.cpp +++ b/src/mc/DwarfExpression.cpp @@ -205,13 +205,19 @@ void execute( // and replace the top of the stack with the computed value // (stack.top() += stack.before_top()). - case DW_OP_plus: - stack.push(stack.pop() + stack.pop()); + case DW_OP_plus: { + intptr_t first = stack.pop(); + intptr_t second = stack.pop(); + stack.push(first + second); break; + } - case DW_OP_mul: - stack.push(stack.pop() * stack.pop()); + case DW_OP_mul: { + intptr_t first = stack.pop(); + intptr_t second = stack.pop(); + stack.push(first * second); break; + } case DW_OP_plus_uconst: stack.top() += op->number; @@ -232,17 +238,26 @@ void execute( break; } - case DW_OP_and: - stack.push(stack.pop() & stack.pop()); + case DW_OP_and: { + intptr_t first = stack.pop(); + intptr_t second = stack.pop(); + stack.push(first & second); break; + } - case DW_OP_or: - stack.push(stack.pop() | stack.pop()); + case DW_OP_or: { + intptr_t first = stack.pop(); + intptr_t second = stack.pop(); + stack.push(first | second); break; + } - case DW_OP_xor: - stack.push(stack.pop() ^ stack.pop()); + case DW_OP_xor: { + intptr_t first = stack.pop(); + intptr_t second = stack.pop(); + stack.push(first ^ second); break; + } case DW_OP_nop: break; -- 2.20.1