Skip to content

Commit 772ff3e

Browse files
committed
Handle null json EVM ASM input
1 parent debc817 commit 772ff3e

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

libevmasm/Assembly.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ Json::Value Assembly::assemblyJSON(std::map<std::string, unsigned> const& _sourc
510510

511511
std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSON(Json::Value const& _json, std::vector<std::string> const& _sourceList, int _level)
512512
{
513+
std::shared_ptr<Assembly> result = std::make_shared<Assembly>(langutil::EVMVersion(), _level == 0, "");
514+
if (_json.isNull())
515+
return std::make_pair(result, std::vector<std::string>());
516+
513517
solRequire(_json.isObject(), AssemblyImportException, "Supplied JSON is not an object.");
514518
static std::set<std::string> const validMembers{".code", ".data", ".auxdata", "sourceList"};
515519
for (auto const& attribute: _json.getMemberNames())
@@ -534,7 +538,6 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
534538
"Member 'sourceList' is only allowed in root JSON object."
535539
);
536540

537-
std::shared_ptr<Assembly> result = std::make_shared<Assembly>(langutil::EVMVersion(), _level == 0, "");
538541
std::vector<std::string> sourceList;
539542
if (_json.isMember("sourceList"))
540543
{

libevmasm/EVMAssemblyStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void EVMAssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::stri
3636
solAssert(!m_evmAssembly);
3737
m_name = _sourceName;
3838
Json::Value assemblyJson;
39-
solRequire(jsonParseStrict(_source, assemblyJson), AssemblyImportException, "Could not parse JSON file.");
39+
solRequire(jsonParse(_source, assemblyJson), AssemblyImportException, "Could not parse JSON file.");
4040
std::tie(m_evmAssembly, m_sourceList) = evmasm::Assembly::fromJSON(assemblyJson);
4141
solRequire(m_evmAssembly != nullptr, AssemblyImportException, "Could not create evm assembly object.");
4242
}

libsolutil/JSON.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string*
144144
return parse(readerBuilder, _input, _json, _errs);
145145
}
146146

147+
bool jsonParse(std::string const& _input, Json::Value& _json, std::string* _errs /* = nullptr */)
148+
{
149+
static Json::CharReaderBuilder readerBuilder;
150+
return parse(readerBuilder, _input, _json, _errs);
151+
}
152+
147153
std::optional<Json::Value> jsonValueByPath(Json::Value const& _node, std::string_view _jsonPath)
148154
{
149155
if (!_node.isObject() || _jsonPath.empty())

libsolutil/JSON.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ std::string jsonPrint(Json::Value const& _input, JsonFormat const& _format);
6969
/// \return \c true if the document was successfully parsed, \c false if an error occurred.
7070
bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr);
7171

72+
bool jsonParse(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr);
73+
7274
/// Retrieves the value specified by @p _jsonPath by from a series of nested JSON dictionaries.
7375
/// @param _jsonPath A dot-separated series of dictionary keys.
7476
/// @param _node The node representing the start of the path.

0 commit comments

Comments
 (0)