aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-04-12 03:12:17 +0800
committerchriseth <chris@ethereum.org>2017-04-25 22:49:04 +0800
commitdfaab73efe1811848a52a218a207f2d4f007a2d8 (patch)
treef2d5ef4459be7bd01101c8485715dda77b0d7dfd /libsolidity/analysis
parentf19e6a09a7b5293c70e98bbe66ab49aa45f76a73 (diff)
downloaddexon-solidity-dfaab73efe1811848a52a218a207f2d4f007a2d8.tar
dexon-solidity-dfaab73efe1811848a52a218a207f2d4f007a2d8.tar.gz
dexon-solidity-dfaab73efe1811848a52a218a207f2d4f007a2d8.tar.bz2
dexon-solidity-dfaab73efe1811848a52a218a207f2d4f007a2d8.tar.lz
dexon-solidity-dfaab73efe1811848a52a218a207f2d4f007a2d8.tar.xz
dexon-solidity-dfaab73efe1811848a52a218a207f2d4f007a2d8.tar.zst
dexon-solidity-dfaab73efe1811848a52a218a207f2d4f007a2d8.zip
Only allow access to local variables and only if they have a stack size of one.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp66
1 files changed, 38 insertions, 28 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 2d6a782a..f26c0a39 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -25,6 +25,7 @@
#include <boost/range/adaptor/reversed.hpp>
#include <libsolidity/ast/AST.h>
#include <libsolidity/inlineasm/AsmAnalysis.h>
+#include <libsolidity/inlineasm/AsmData.h>
using namespace std;
using namespace dev;
@@ -637,50 +638,59 @@ bool TypeChecker::visit(InlineAssembly const& _inlineAssembly)
auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier);
if (ref == _inlineAssembly.annotation().externalReferences.end())
return size_t(-1);
- size_t valueSize = size_t(-1);
Declaration const* declaration = ref->second.declaration;
solAssert(!!declaration, "");
+ if (auto var = dynamic_cast<VariableDeclaration const*>(declaration))
+ {
+ if (!var->isLocalVariable())
+ {
+ typeError(_identifier.location, "Only local variables are supported.");
+ return size_t(-1);
+ }
+ if (var->type()->dataStoredIn(DataLocation::Storage))
+ {
+ typeError(_identifier.location, "Storage reference variables are not supported.");
+ return size_t(-1);
+ }
+ if (var->type()->sizeOnStack() != 1)
+ {
+ typeError(_identifier.location, "Only types that use one stack slot are supported.");
+ return size_t(-1);
+ }
+ if (var->isConstant())
+ {
+ typeError(_identifier.location, "Constant variables not supported by inline assembly.");
+ return size_t(-1);
+ }
+ }
+ else if (_context == assembly::IdentifierContext::LValue)
+ {
+ typeError(_identifier.location, "Only local variables can be assigned to in inline assembly.");
+ return size_t(-1);
+ }
+
if (_context == assembly::IdentifierContext::RValue)
{
solAssert(!!declaration->type(), "Type of declaration required but not yet determined.");
if (dynamic_cast<FunctionDefinition const*>(declaration))
- valueSize = 1;
- else if (auto var = dynamic_cast<VariableDeclaration const*>(declaration))
{
- if (var->isConstant())
- fatalTypeError(SourceLocation(), "Constant variables not yet implemented for inline assembly.");
- if (var->isLocalVariable())
- valueSize = var->type()->sizeOnStack();
- else if (!var->type()->isValueType())
- valueSize = 1;
- else
- // We cannot use `sizeOnStack()` here because we do not insert the value
- // into inline assembly but rather the storage location.
- valueSize = 2; // slot number, intra slot offset
+ }
+ else if (dynamic_cast<VariableDeclaration const*>(declaration))
+ {
}
else if (auto contract = dynamic_cast<ContractDefinition const*>(declaration))
{
if (!contract->isLibrary())
+ {
+ typeError(_identifier.location, "Expected a library.");
return size_t(-1);
- valueSize = 1;
- }
- else
- return size_t(-1);
- }
- else
- {
- // lvalue context
- if (auto varDecl = dynamic_cast<VariableDeclaration const*>(declaration))
- {
- if (!varDecl->isLocalVariable())
- return size_t(-1); // only local variables are inline-assembly lvalues
- valueSize = size_t(declaration->type()->sizeOnStack());
+ }
}
else
return size_t(-1);
}
- ref->second.valueSize = valueSize;
- return valueSize;
+ ref->second.valueSize = 1;
+ return size_t(1);
};
assembly::AsmAnalyzer::Scopes scopes;
assembly::AsmAnalyzer analyzer(scopes, m_errors, identifierAccess);