Skip to content

Commit 470d988

Browse files
committed
evaluator: Fix array and pointer placements not being out-of-bounds checked
1 parent 72f7253 commit 470d988

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/source/pl/core/ast/ast_node_array_variable_decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ namespace pl::core::ast {
7070
[this](const std::shared_ptr<ptrn::Pattern>&) -> u64 { err::E0005.throwError("Cannot use string as placement offset.", "Try using a integral value instead.", this->getLocation()); },
7171
[](auto &&offset) -> u64 { return u64(offset); }
7272
}, offset->getValue()));
73+
74+
if (evaluator->getReadOffset() < evaluator->getDataBaseAddress() || evaluator->getReadOffset() > evaluator->getDataBaseAddress() + evaluator->getDataSize())
75+
err::E0005.throwError(fmt::format("Cannot place variable '{}' at out of bounds address 0x{:08X}", this->m_name, evaluator->getReadOffset()), { }, this->getLocation());
7376
}
7477

7578
if (evaluator->getSectionId() == ptrn::Pattern::PatternLocalSectionId || evaluator->getSectionId() == ptrn::Pattern::HeapSectionId) {

lib/source/pl/core/ast/ast_node_pointer_variable_decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ namespace pl::core::ast {
5757
[this](const std::shared_ptr<ptrn::Pattern> &) -> u64 { err::E0005.throwError("Cannot use string as placement offset.", "Try using a integral value instead.", this->getLocation()); },
5858
[](auto &&offset) -> u64 { return u64(offset); }
5959
}, offset->getValue()));
60+
61+
if (evaluator->getReadOffset() < evaluator->getDataBaseAddress() || evaluator->getReadOffset() > evaluator->getDataBaseAddress() + evaluator->getDataSize())
62+
err::E0005.throwError(fmt::format("Cannot place variable '{}' at out of bounds address 0x{:08X}", this->m_name, evaluator->getReadOffset()), { }, this->getLocation());
6063
}
6164

6265
auto pointerStartOffset = evaluator->getReadOffset();

0 commit comments

Comments
 (0)