From 0ec17b6026298dc150099b66a2cecad0fe561d1b Mon Sep 17 00:00:00 2001 From: Olek <115580134+oleks-rip@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:58:25 -0500 Subject: [PATCH] fix: check for valid ammID field in amm_info RPC (#5188) --- src/test/rpc/AMMInfo_test.cpp | 19 +++++++++++++++++++ src/xrpld/rpc/handlers/AMMInfo.cpp | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/test/rpc/AMMInfo_test.cpp b/src/test/rpc/AMMInfo_test.cpp index e4523bb0473..c1e059a3ead 100644 --- a/src/test/rpc/AMMInfo_test.cpp +++ b/src/test/rpc/AMMInfo_test.cpp @@ -316,6 +316,24 @@ class AMMInfo_test : public jtx::AMMTestBase }); } + void + testInvalidAmmField() + { + using namespace jtx; + testcase("Invalid amm field"); + + testAMM([&](AMM& amm, Env&) { + auto const resp = amm.ammRpcInfo( + std::nullopt, + jss::validated.c_str(), + std::nullopt, + std::nullopt, + gw); + BEAST_EXPECT( + resp.isMember("error") && resp["error"] == "actNotFound"); + }); + } + void run() override { @@ -323,6 +341,7 @@ class AMMInfo_test : public jtx::AMMTestBase testSimpleRpc(); testVoteAndBid(); testFreeze(); + testInvalidAmmField(); } }; diff --git a/src/xrpld/rpc/handlers/AMMInfo.cpp b/src/xrpld/rpc/handlers/AMMInfo.cpp index aad8faea213..9d5b20f1d63 100644 --- a/src/xrpld/rpc/handlers/AMMInfo.cpp +++ b/src/xrpld/rpc/handlers/AMMInfo.cpp @@ -132,6 +132,8 @@ doAMMInfo(RPC::JsonContext& context) if (!sle) return Unexpected(rpcACT_MALFORMED); ammID = sle->getFieldH256(sfAMMID); + if (ammID->isZero()) + return Unexpected(rpcACT_NOT_FOUND); } if (params.isMember(jss::account))