Skip to content

Commit 60edcf5

Browse files
committed
add range check to RPC to be able to correctly inform the RPC user that the command he has send has a problem
1 parent 7808370 commit 60edcf5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/clientrpc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,16 @@ CClientRpc::CClientRpc ( CClient* pClient, CRpcServer* pRpcServer, QObject* pare
334334
/// @result {string} result - Always "ok".
335335
pRpcServer->HandleMethod ( "jamulusclient/setFaderLevel", [=] ( const QJsonObject& params, QJsonObject& response ) {
336336
auto jsonChannelIndex = params["channelIndex"];
337-
if ( !jsonChannelIndex.isDouble() )
337+
if ( !jsonChannelIndex.isDouble() || ( jsonChannelIndex.toInt() < 0 ) || ( jsonChannelIndex.toInt() > MAX_NUM_CHANNELS ) )
338338
{
339-
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: channelIndex is not a number" );
339+
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: channelIndex is not a number or out-of-range" );
340340
return;
341341
}
342342

343343
auto jsonLevel = params["level"];
344-
if ( !jsonLevel.isDouble() )
344+
if ( !jsonLevel.isDouble() || ( jsonLevel.toInt() < 0 ) || ( jsonLevel.toInt() > 100 ) )
345345
{
346-
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: level is not a number" );
346+
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: level is not a number or out-of-range" );
347347
return;
348348
}
349349

0 commit comments

Comments
 (0)