From 33fca646ceac211579b7675459cfa34257b47f23 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Mon, 26 Jun 2023 08:58:21 -0400 Subject: [PATCH 1/4] accountinfo invalid signer_list -> invalidParams --- src/ripple/rpc/handlers/AccountInfo.cpp | 9 +++++++++ src/test/rpc/AccountInfo_test.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index 3af70324bcd..633b7eedb5a 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -125,6 +125,15 @@ doAccountInfo(RPC::JsonContext& context) } result[jss::account_flags] = std::move(acctFlags); + // The document states that signer_lists is a bool, however + // assigning any string value works. Do not allow this + // This for api v2 onwards + if (!params[jss::signer_lists].isBool() && context.apiVersion > 1) + { + RPC::inject_error(rpcINVALID_PARAMS, result); + return result; + } + // Return SignerList(s) if that is requested. if (params.isMember(jss::signer_lists) && params[jss::signer_lists].asBool()) diff --git a/src/test/rpc/AccountInfo_test.cpp b/src/test/rpc/AccountInfo_test.cpp index b8e479225d1..3f68d7953fe 100644 --- a/src/test/rpc/AccountInfo_test.cpp +++ b/src/test/rpc/AccountInfo_test.cpp @@ -217,6 +217,10 @@ class AccountInfo_test : public beast::unit_test::suite "\"api_version\": 2, \"account\": \"" + alice.human() + "\", " + "\"signer_lists\": true }"; + auto const withSignersAsString = std::string("{ ") + + "\"api_version\": 2, \"account\": \"" + alice.human() + "\", " + + "\"signer_lists\": asdfggh }"; + // Alice has no SignerList yet. { // account_info without the "signer_lists" argument. @@ -263,6 +267,12 @@ class AccountInfo_test : public beast::unit_test::suite auto const& entry0 = signerEntries[0u][sfSignerEntry.jsonName]; BEAST_EXPECT(entry0[sfSignerWeight.jsonName] == 3); } + { + // account_info with "signer_lists" as not bool should error out + auto const info = env.rpc("json", "account_info", withSignersAsString); + BEAST_EXPECT(info[jss::status] == "error"); + BEAST_EXPECT(info[jss::error] == "invalidParams"); + } // Give alice a big signer list Account const demon{"demon"}; From 7c970dbf355f2ed5c5696cf3591bdf054678f434 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Thu, 29 Jun 2023 10:22:00 -0400 Subject: [PATCH 2/4] small change for scott's comment --- src/ripple/rpc/handlers/AccountInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index 633b7eedb5a..4ede9ddbfc9 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -127,7 +127,7 @@ doAccountInfo(RPC::JsonContext& context) // The document states that signer_lists is a bool, however // assigning any string value works. Do not allow this - // This for api v2 onwards + // this for api v2 onwards if (!params[jss::signer_lists].isBool() && context.apiVersion > 1) { RPC::inject_error(rpcINVALID_PARAMS, result); From d626a6b6d324f0102d3b3fa314e6812261cb89a0 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Thu, 29 Jun 2023 11:51:55 -0400 Subject: [PATCH 3/4] comment change --- src/ripple/rpc/handlers/AccountInfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ripple/rpc/handlers/AccountInfo.cpp b/src/ripple/rpc/handlers/AccountInfo.cpp index 4ede9ddbfc9..13487dd2dae 100644 --- a/src/ripple/rpc/handlers/AccountInfo.cpp +++ b/src/ripple/rpc/handlers/AccountInfo.cpp @@ -126,8 +126,8 @@ doAccountInfo(RPC::JsonContext& context) result[jss::account_flags] = std::move(acctFlags); // The document states that signer_lists is a bool, however - // assigning any string value works. Do not allow this - // this for api v2 onwards + // assigning any string value works. Do not allow this. + // This check is for api Version 2 onwards only if (!params[jss::signer_lists].isBool() && context.apiVersion > 1) { RPC::inject_error(rpcINVALID_PARAMS, result); From a15df565f8b99e94988023c160438d28fc565407 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Thu, 29 Jun 2023 11:58:54 -0400 Subject: [PATCH 4/4] clang format --- src/test/rpc/AccountInfo_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/rpc/AccountInfo_test.cpp b/src/test/rpc/AccountInfo_test.cpp index 3f68d7953fe..9108ac6360a 100644 --- a/src/test/rpc/AccountInfo_test.cpp +++ b/src/test/rpc/AccountInfo_test.cpp @@ -269,7 +269,8 @@ class AccountInfo_test : public beast::unit_test::suite } { // account_info with "signer_lists" as not bool should error out - auto const info = env.rpc("json", "account_info", withSignersAsString); + auto const info = + env.rpc("json", "account_info", withSignersAsString); BEAST_EXPECT(info[jss::status] == "error"); BEAST_EXPECT(info[jss::error] == "invalidParams"); }