Skip to content

Commit ef0e30e

Browse files
Mariusz-Treladnotestein
authored andcommitted
Issue #734 - Broken peers.json file can block p2p from working without any message
1 parent e58cba5 commit ef0e30e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

libraries/fc/src/io/json.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ namespace fc
170170
case 0x04:
171171
FC_THROW_EXCEPTION(parse_error_exception, "EOF before closing '\"' in string '${token}'",
172172
("token", result));
173+
case EOF:
174+
FC_THROW_EXCEPTION( eof_exception, "unexpected end of file" );
173175
case '"':
174176
in.get();
175177
return result;

tests/unit/tests/serialization_tests.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -883,5 +883,28 @@ BOOST_AUTO_TEST_CASE( unpack_array_limit_test )
883883
FC_LOG_AND_RETHROW();
884884
}
885885

886+
BOOST_AUTO_TEST_CASE( incorrect_json_deserialization )
887+
{
888+
try
889+
{
890+
std::string _content =
891+
R"([{
892+
"endpoint": "2.59.255.86:2001",
893+
"last_seen_time": "2024-11-13T10:00:10",
894+
"last_connection_disposition": "last_connection_handshaking_failed",
895+
"la
896+
)";
897+
898+
const std::string _path = "output.txt";
899+
std::ofstream _file( _path );
900+
_file << _content;
901+
_file.close();
902+
903+
BOOST_REQUIRE_THROW( fc::json::from_string( _content, fc::json::format_validation_mode::full ), fc::parse_error_exception );
904+
BOOST_REQUIRE_THROW( fc::json::from_file( _path, fc::json::format_validation_mode::full ), fc::parse_error_exception );
905+
}
906+
FC_LOG_AND_RETHROW();
907+
}
908+
886909
BOOST_AUTO_TEST_SUITE_END()
887910
#endif

0 commit comments

Comments
 (0)