diff options
author | LianaHus <liana@ethdev.com> | 2015-09-09 23:35:27 +0800 |
---|---|---|
committer | LianaHus <liana@ethdev.com> | 2015-09-15 17:37:59 +0800 |
commit | b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2 (patch) | |
tree | 75fc66027312841c76d42443a52344ea92758b7f | |
parent | 626a57826cd46c25f78cc5cf22e828b3a21b419c (diff) | |
download | dexon-solidity-b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2.tar dexon-solidity-b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2.tar.gz dexon-solidity-b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2.tar.bz2 dexon-solidity-b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2.tar.lz dexon-solidity-b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2.tar.xz dexon-solidity-b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2.tar.zst dexon-solidity-b7b16b153b7763237ebd8d5b4db8aad4f4b2f4f2.zip |
added compile time check for out of bounds access for ordinary arrays
todo: check for dynamicaly sized arrays
Conflicts:
libsolidity/ExpressionCompiler.cpp
-rw-r--r-- | libsolidity/ExpressionCompiler.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index b22a78dc..06cccc24 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -821,6 +821,8 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess) _indexAccess.baseExpression().accept(*this); Type const& baseType = *_indexAccess.baseExpression().type(); + Type const& indexType = *_indexAccess.indexExpression()->type(); + if (baseType.category() == Type::Category::Mapping) { // stack: storage_base_ref @@ -861,8 +863,20 @@ bool ExpressionCompiler::visit(IndexAccess const& _indexAccess) solAssert(_indexAccess.indexExpression(), "Index expression expected."); _indexAccess.indexExpression()->accept(*this); + + // check for dynamically sized arrays should be done after memberAccess visit to have length + if ( + (indexType.category() == Type::Category::IntegerConstant) && + ((arrayType.isDynamicallySized() && arrayType.length()) || !arrayType.isDynamicallySized())) + { + IntegerConstantType const& constant = dynamic_cast<IntegerConstantType const&>(indexType); + if (arrayType.length() < constant.literalValue(nullptr)) + BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Out of bounds access.")); + } + // stack layout: <base_ref> [<length>] <index> ArrayUtils(m_context).accessIndex(arrayType); + switch (arrayType.location()) { case DataLocation::Storage: |