Skip to content

Commit 0ec17b6

Browse files
authored
fix: check for valid ammID field in amm_info RPC (XRPLF#5188)
1 parent 838978b commit 0ec17b6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/test/rpc/AMMInfo_test.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,32 @@ class AMMInfo_test : public jtx::AMMTestBase
316316
});
317317
}
318318

319+
void
320+
testInvalidAmmField()
321+
{
322+
using namespace jtx;
323+
testcase("Invalid amm field");
324+
325+
testAMM([&](AMM& amm, Env&) {
326+
auto const resp = amm.ammRpcInfo(
327+
std::nullopt,
328+
jss::validated.c_str(),
329+
std::nullopt,
330+
std::nullopt,
331+
gw);
332+
BEAST_EXPECT(
333+
resp.isMember("error") && resp["error"] == "actNotFound");
334+
});
335+
}
336+
319337
void
320338
run() override
321339
{
322340
testErrors();
323341
testSimpleRpc();
324342
testVoteAndBid();
325343
testFreeze();
344+
testInvalidAmmField();
326345
}
327346
};
328347

src/xrpld/rpc/handlers/AMMInfo.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ doAMMInfo(RPC::JsonContext& context)
132132
if (!sle)
133133
return Unexpected(rpcACT_MALFORMED);
134134
ammID = sle->getFieldH256(sfAMMID);
135+
if (ammID->isZero())
136+
return Unexpected(rpcACT_NOT_FOUND);
135137
}
136138

137139
if (params.isMember(jss::account))

0 commit comments

Comments
 (0)