Skip to content

Fix UB when emiting warning for empty contracts with custom layout near the end of storage#16682

Open
matheusaaguiar wants to merge 2 commits into
developfrom
fix_custom_storage_layout_warning_UB
Open

Fix UB when emiting warning for empty contracts with custom layout near the end of storage#16682
matheusaaguiar wants to merge 2 commits into
developfrom
fix_custom_storage_layout_warning_UB

Conversation

@matheusaaguiar
Copy link
Copy Markdown
Contributor

Fix #16681 and #16678.

@matheusaaguiar matheusaaguiar force-pushed the fix_custom_storage_layout_warning_UB branch from 5988dfb to 2f481bc Compare May 7, 2026 06:22
@matheusaaguiar matheusaaguiar requested review from clonker and msooseth May 7, 2026 15:29
msooseth
msooseth previously approved these changes May 7, 2026
Copy link
Copy Markdown
Contributor

@msooseth msooseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I am bad at reviews.

@matheusaaguiar matheusaaguiar force-pushed the fix_custom_storage_layout_warning_UB branch from 2f481bc to 263706a Compare May 7, 2026 17:42
for (ContractDefinition const* baseContract: ranges::actions::reverse(_contract.annotation().linearizedBaseContracts))
for (VariableDeclaration const* stateVariable: ranges::actions::reverse(baseContract->stateVariables()))
if (stateVariable->referenceLocation() == VariableDeclaration::Location::Unspecified)
for (ContractDefinition const* baseContract: _contract.annotation().linearizedBaseContracts)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that linearizedBaseContracts is in order of the most-derived to most-base.
The last storage variable of the most-derived is the one which is closer to the end of storage.

Comment on lines +219 to +220
!stateVariable->isConstant() &&
!stateVariable->immutable()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need this to filter constants and immutables which are stored directly in the bytecode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIGSEGV in findLastStorageVariable for contract C layout at 2**256 - 1

2 participants