fix connect

This commit is contained in:
Mayukha Vadari
2025-11-17 17:58:57 +05:30
parent fb5d878b86
commit 9e23d50339
2 changed files with 31 additions and 7 deletions

View File

@@ -2413,8 +2413,16 @@ static RPCCallTestData const rpcCallTestArray[] = {
"ThereIsNoCheckingOnTheIPFormat",
"-1",
},
RPCCallTestData::bad_cast,
R"()"},
RPCCallTestData::no_exception,
R"({
"method" : "connect",
"params" : [
{
"error" : "invalidParams",
"error_message" : "Invalid field 'port'."
}
]
})"},
{// Note: this should return an error but not throw.
"connect: port too large.",
__LINE__,
@@ -2423,8 +2431,16 @@ static RPCCallTestData const rpcCallTestArray[] = {
"ThereIsNoCheckingOnTheIPFormat",
"4294967296",
},
RPCCallTestData::bad_cast,
R"()"},
RPCCallTestData::no_exception,
R"({
"method" : "connect",
"params" : [
{
"error" : "invalidParams",
"error_message" : "Invalid field 'port'."
}
]
})"},
// consensus_info
// --------------------------------------------------------------

View File

@@ -455,7 +455,10 @@ private:
if (jvParams.size() == 2)
{
jvRequest[jss::ip] = ip;
jvRequest[jss::port] = jvParams[1u].asUInt();
if (auto port = jvParseUInt(jvParams[1u]))
jvRequest[jss::port] = *port;
else
return RPC::invalid_field_error(jss::port);
return jvRequest;
}
@@ -464,8 +467,13 @@ private:
{
std::size_t colon = ip.find_last_of(":");
jvRequest[jss::ip] = std::string{ip, 0, colon};
jvRequest[jss::port] =
Json::Value{std::string{ip, colon + 1}}.asUInt();
std::uint32_t port;
if (beast::lexicalCastChecked(port, std::string{ip, colon + 1}))
jvRequest[jss::port] = port;
else
return RPC::invalid_field_error(jss::port);
return jvRequest;
}