aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-08-08 05:29:21 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-08-08 05:29:21 +0800
commit3064bd17bc9393d0761fa65ac64c152d7d02319c (patch)
tree910e76e8894511cddf0ad30512b007142b2928b1
parenta99347e9f0b9b3a18da598dd49d5816e37d9f22e (diff)
downloaddexon-solidity-3064bd17bc9393d0761fa65ac64c152d7d02319c.tar.gz
dexon-solidity-3064bd17bc9393d0761fa65ac64c152d7d02319c.tar.zst
dexon-solidity-3064bd17bc9393d0761fa65ac64c152d7d02319c.zip
Assert that type identifier contains only valid characters
-rw-r--r--libsolidity/ast/Types.cpp11
-rw-r--r--libsolidity/ast/Types.h2
2 files changed, 12 insertions, 1 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 3eccc6d4..abd3bd87 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -254,6 +254,17 @@ string Type::escapeIdentifier(string const& _identifier)
return ret;
}
+string Type::identifier() const
+{
+ string ret = escapeIdentifier(richIdentifier());
+ solAssert(ret.find_first_of("0123456789") != 0, "Identifier cannot start with a number.");
+ solAssert(
+ ret.find_first_not_of("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMONPQRSTUVWXYZ_$") == string::npos,
+ "Identifier contains invalid characters."
+ );
+ return ret;
+}
+
TypePointer Type::fromElementaryTypeName(ElementaryTypeNameToken const& _type)
{
solAssert(Token::isElementaryTypeName(_type.token()),
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 09323d05..1fa2b2f5 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -172,7 +172,7 @@ public:
/// only if they have the same identifier.
/// The identifier should start with "t_".
/// Will not contain any character which would be invalid as an identifier.
- std::string identifier() const { return escapeIdentifier(richIdentifier()); }
+ std::string identifier() const;
/// More complex identifier strings use "parentheses", where $_ is interpreted as as
/// "opening parenthesis", _$ as "closing parenthesis", _$_ as "comma" and any $ that