diff --git a/src/test/app/LedgerReplay_test.cpp b/src/test/app/LedgerReplay_test.cpp index 810d93e6e1..49857e02ca 100644 --- a/src/test/app/LedgerReplay_test.cpp +++ b/src/test/app/LedgerReplay_test.cpp @@ -939,6 +939,46 @@ struct LedgerReplayer_test : public beast::unit_test::Suite BEAST_EXPECT(!reply->has_error()); BEAST_EXPECT(server.msgHandler.processProofPathResponse(reply)); + { + // bad reply: invalid hash/key sizes + { + // reply with undersized ledgerhash (31 bytes) + auto bad = std::make_shared(*reply); + bad->set_ledgerhash(std::string(31, '\x01')); + BEAST_EXPECT(!server.msgHandler.processProofPathResponse(bad)); + } + { + // reply with oversized ledgerhash (33 bytes) + auto bad = std::make_shared(*reply); + bad->set_ledgerhash(std::string(33, '\x01')); + BEAST_EXPECT(!server.msgHandler.processProofPathResponse(bad)); + } + { + // reply with empty ledgerhash + auto bad = std::make_shared(*reply); + bad->set_ledgerhash(std::string()); + BEAST_EXPECT(!server.msgHandler.processProofPathResponse(bad)); + } + { + // reply with undersized key (31 bytes) + auto bad = std::make_shared(*reply); + bad->set_key(std::string(31, '\x01')); + BEAST_EXPECT(!server.msgHandler.processProofPathResponse(bad)); + } + { + // reply with oversized key (33 bytes) + auto bad = std::make_shared(*reply); + bad->set_key(std::string(33, '\x01')); + BEAST_EXPECT(!server.msgHandler.processProofPathResponse(bad)); + } + { + // reply with empty key + auto bad = std::make_shared(*reply); + bad->set_key(std::string()); + BEAST_EXPECT(!server.msgHandler.processProofPathResponse(bad)); + } + } + { // bad reply // bad header @@ -988,6 +1028,28 @@ struct LedgerReplayer_test : public beast::unit_test::Suite BEAST_EXPECT(!reply->has_error()); BEAST_EXPECT(server.msgHandler.processReplayDeltaResponse(reply)); + { + // bad reply: invalid hash sizes + { + // reply with undersized ledgerhash (31 bytes) + auto bad = std::make_shared(*reply); + bad->set_ledgerhash(std::string(31, '\x01')); + BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(bad)); + } + { + // reply with oversized ledgerhash (33 bytes) + auto bad = std::make_shared(*reply); + bad->set_ledgerhash(std::string(33, '\x01')); + BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(bad)); + } + { + // reply with empty ledgerhash + auto bad = std::make_shared(*reply); + bad->set_ledgerhash(std::string()); + BEAST_EXPECT(!server.msgHandler.processReplayDeltaResponse(bad)); + } + } + { // bad reply // bad header diff --git a/src/test/basics/base_uint_test.cpp b/src/test/basics/base_uint_test.cpp index 5816b4eb59..08466a6ad2 100644 --- a/src/test/basics/base_uint_test.cpp +++ b/src/test/basics/base_uint_test.cpp @@ -117,6 +117,30 @@ struct base_uint_test : beast::unit_test::Suite } } + void + testFromRawSizeMismatch() + { + testcase("base_uint: fromRaw size mismatch"); + + // Container smaller than the base_uint (8 bytes vs 12 bytes for + // test96). Only the first 8 bytes are copied; the remaining 4 bytes + // stay zero. + { + Blob const tooSmall{1, 2, 3, 4, 5, 6, 7, 8}; + test96 const result = test96::fromRaw(tooSmall); + BEAST_EXPECT(to_string(result) == "010203040506070800000000"); + } + + // Container larger than the base_uint (16 bytes vs 12 bytes for + // test96). Only the first 12 bytes are copied; the extra bytes are + // ignored. + { + Blob const tooBig{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; + test96 const result = test96::fromRaw(tooBig); + BEAST_EXPECT(to_string(result) == "0102030405060708090A0B0C"); + } + } + void run() override { @@ -125,6 +149,10 @@ struct base_uint_test : beast::unit_test::Suite static_assert(!std::is_constructible_v>); static_assert(!std::is_assignable_v>); +#ifdef NDEBUG + testFromRawSizeMismatch(); +#endif + testComparisons(); // used to verify set insertion (hashing required)