diff options
| author | Adrian Prantl <aprantl@apple.com> | 2024-12-11 14:16:23 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-11 14:16:23 -0800 |
| commit | 2470cfab63ac14df02dc6df686fcae7b1a4eb84f (patch) | |
| tree | 084bb6718e8e08bad461e22214d8d67178b8fa5f /lldb/source/DataFormatters/FormatterBytecode.cpp | |
| parent | 6f013dbced67948119fe9ca71336f0284975ba4f (diff) | |
[lldb] Disallow left shifts of negative values in the interpreter (#119620)
This trips UBSAN and probably isn't partiuclarly useful either.
Diffstat (limited to 'lldb/source/DataFormatters/FormatterBytecode.cpp')
| -rw-r--r-- | lldb/source/DataFormatters/FormatterBytecode.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lldb/source/DataFormatters/FormatterBytecode.cpp b/lldb/source/DataFormatters/FormatterBytecode.cpp index f344fbaff6f0..e49c75067818 100644 --- a/lldb/source/DataFormatters/FormatterBytecode.cpp +++ b/lldb/source/DataFormatters/FormatterBytecode.cpp @@ -379,7 +379,7 @@ llvm::Error Interpret(std::vector<ControlStackElement> &control, BINOP_CHECKZERO(%); continue; case op_shl: -#define SHIFTOP(OP) \ +#define SHIFTOP(OP, LEFT) \ { \ TYPE_CHECK(Any, UInt); \ uint64_t y = data.Pop<uint64_t>(); \ @@ -390,16 +390,18 @@ llvm::Error Interpret(std::vector<ControlStackElement> &control, data.Push(x OP y); \ } else if (std::holds_alternative<int64_t>(data.back())) { \ int64_t x = data.Pop<int64_t>(); \ + if (x < 0 && LEFT) \ + return error("left shift of negative value"); \ if (y > 64) \ return error("shift out of bounds"); \ data.Push(x OP y); \ } else \ return error("unsupported data types"); \ } - SHIFTOP(<<); + SHIFTOP(<<, true); continue; case op_shr: - SHIFTOP(<<); + SHIFTOP(>>, false); continue; case op_and: BINOP(&); |
