From cbc66f931da1046b3980c2c7c6b64c2f2ac358e2 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 18 Mar 2026 22:58:20 -0700 Subject: Fix operand list iterators being validated when appending new instructions The iterators now store an offset into the operand storage, rather than a pointer. Deferencing the iterator retrieves the value at that offset from the IL function. This issue existed prior to the operand list storage refactor, but became easier to hit after that change. The separate operand list vector is smaller and thus more likely to reallocate when a new instruction is appended. --- highlevelilinstruction.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'highlevelilinstruction.cpp') diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index ad8f416d..7f4bad39 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -288,14 +288,18 @@ bool HighLevelILIntegerList::ListIterator::operator<(const ListIterator& a) cons HighLevelILIntegerList::ListIterator& HighLevelILIntegerList::ListIterator::operator++() { count--; - cur++; + offset++; return *this; } uint64_t HighLevelILIntegerList::ListIterator::operator*() { - return *cur; +#ifdef BINARYNINJACORE_LIBRARY + return function->GetOperand(offset); +#else + return BNHighLevelILGetOperand(function->GetObject(), offset); +#endif } @@ -303,11 +307,7 @@ HighLevelILIntegerList::HighLevelILIntegerList( HighLevelILFunction* func, size_t offset, size_t count) { m_start.function = func; -#ifdef BINARYNINJACORE_LIBRARY - m_start.cur = func->GetOperandPointer(offset); -#else - m_start.cur = BNHighLevelILGetOperandPointer(func->GetObject(), offset); -#endif + m_start.offset = offset; m_start.count = count; } @@ -322,7 +322,7 @@ HighLevelILIntegerList::const_iterator HighLevelILIntegerList::end() const { const_iterator result; result.function = m_start.function; - result.cur = m_start.cur + m_start.count; + result.offset = m_start.offset + m_start.count; result.count = 0; return result; } @@ -338,7 +338,11 @@ uint64_t HighLevelILIntegerList::operator[](size_t i) const { if (i >= size()) throw HighLevelILInstructionAccessException(); - return m_start.cur[i]; +#ifdef BINARYNINJACORE_LIBRARY + return m_start.function->GetOperand(m_start.offset + i); +#else + return BNHighLevelILGetOperand(m_start.function->GetObject(), m_start.offset + i); +#endif } -- cgit v1.3.1