aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-01-25 18:33:09 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-01-25 19:28:09 +0800
commit900c56d996472cb2053b69c7104ef007c13b1e80 (patch)
treeb6061f8d355c5e64858e16bd9c602c741a56a423
parentba9a04500217e301bec63cab4e0c0f1d9322646d (diff)
downloaddexon-solidity-900c56d996472cb2053b69c7104ef007c13b1e80.tar.gz
dexon-solidity-900c56d996472cb2053b69c7104ef007c13b1e80.tar.zst
dexon-solidity-900c56d996472cb2053b69c7104ef007c13b1e80.zip
Do not allow shadowing inline assembly instructions with variables
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp11
-rw-r--r--libsolidity/inlineasm/AsmParser.h1
3 files changed, 12 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md
index 7dd607d8..60def101 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -10,6 +10,7 @@ Features:
Bugfixes:
* Code generator: Allow recursive structs.
+ * Inline assembly: reject shadowing instructions by variables.
* Type checker: Allow multiple events of the same name (but with different arities or argument types)
### 0.4.8 (2017-01-13)
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index ef3da255..c0efb651 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -130,7 +130,7 @@ assembly::Statement Parser::parseExpression()
return operation;
}
-assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
+std::map<string, dev::solidity::Instruction> Parser::getInstructions()
{
// Allowed instructions, lowercase names.
static map<string, dev::solidity::Instruction> s_instructions;
@@ -151,6 +151,12 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
// add alias for selfdestruct
s_instructions["selfdestruct"] = solidity::Instruction::SUICIDE;
}
+ return s_instructions;
+}
+
+assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
+{
+ map<string, dev::solidity::Instruction> s_instructions = getInstructions();
Statement ret;
switch (m_scanner->currentToken())
@@ -204,9 +210,12 @@ assembly::Statement Parser::parseElementaryOperation(bool _onlySinglePusher)
assembly::VariableDeclaration Parser::parseVariableDeclaration()
{
+ map<string, dev::solidity::Instruction> s_instructions = getInstructions();
VariableDeclaration varDecl = createWithLocation<VariableDeclaration>();
expectToken(Token::Let);
varDecl.name = m_scanner->currentLiteral();
+ if (s_instructions.count(varDecl.name))
+ fatalParserError("Cannot shadow instructions with variable declaration.");
expectToken(Token::Identifier);
expectToken(Token::Colon);
expectToken(Token::Assign);
diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h
index 8b56ab90..764c53f6 100644
--- a/libsolidity/inlineasm/AsmParser.h
+++ b/libsolidity/inlineasm/AsmParser.h
@@ -64,6 +64,7 @@ protected:
Statement parseStatement();
/// Parses a functional expression that has to push exactly one stack element
Statement parseExpression();
+ std::map<std::string, dev::solidity::Instruction> getInstructions();
Statement parseElementaryOperation(bool _onlySinglePusher = false);
VariableDeclaration parseVariableDeclaration();
FunctionalInstruction parseFunctionalInstruction(Statement&& _instruction);