Skip to content

Commit

Permalink
Properly validate invalid hex characters in JSONIO libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Feb 28, 2018
1 parent 83fec02 commit 7897301
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,20 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
if (!jsonSourceName.isObject())
return formatFatalError("JSONError", "library entry is not a JSON object.");
for (auto const& library: jsonSourceName.getMemberNames())
// @TODO use libraries only for the given source
libraries[library] = h160(jsonSourceName[library].asString());
{
try
{
// @TODO use libraries only for the given source
libraries[library] = h160(jsonSourceName[library].asString());
}
catch (dev::BadHexCharacter)
{
return formatFatalError(
"JSONError",
"Invalid library address (\"" + jsonSourceName[library].asString() + "\") supplied."
);
}
}
}
m_compilerStack.setLibraries(libraries);

Expand Down
23 changes: 23 additions & 0 deletions test/libsolidity/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,29 @@ BOOST_AUTO_TEST_CASE(libraries_invalid_entry)
BOOST_CHECK(containsError(result, "JSONError", "library entry is not a JSON object."));
}

BOOST_AUTO_TEST_CASE(libraries_invalid_hex)
{
char const* input = R"(
{
"language": "Solidity",
"settings": {
"libraries": {
"library.sol": {
"L": "0x4200000000000000000000000000000000000xx1"
}
}
},
"sources": {
"empty": {
"content": ""
}
}
}
)";
Json::Value result = compile(input);
BOOST_CHECK(containsError(result, "JSONError", "Invalid library address (\"0x4200000000000000000000000000000000000xx1\") supplied."));
}

BOOST_AUTO_TEST_CASE(libraries_various_addresses)
{
char const* input = R"(
Expand Down

0 comments on commit 7897301

Please sign in to comment.