Skip to content

Commit ac06f67

Browse files
committed
Added sanity checks for private chat message string
1 parent 8477ae0 commit ac06f67

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/serverrpc.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747

4848
#include "serverrpc.h"
4949

50+
/* Definitions ****************************************************************/
51+
#define INVALID_CLIENT_ID -1
52+
5053
CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* parent ) : QObject ( parent )
5154
{
5255
// API doc already part of CClientRpc
@@ -299,15 +302,17 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare
299302
/// @param {number} params.id - The client's channel id.
300303
/// @result {string} result - Always "ok".
301304
pRpcServer->HandleMethod ( "jamulusserver/privateChatMessage", [=] ( const QJsonObject& params, QJsonObject& response ) {
302-
auto jsonChatMessage = params["chatMessage"];
303-
const int id = params["id"].toInt();
304-
if ( !jsonChatMessage.isString() )
305+
auto jsonChatMessage = params["chatMessage"];
306+
const int id = params["id"].toInt ( INVALID_CLIENT_ID );
307+
const QString chatMessage = jsonChatMessage.toString();
308+
if ( chatMessage.isEmpty() || chatMessage.size() > MAX_LEN_CHAT_TEXT )
305309
{
306-
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: chatMessage is not a string" );
310+
response["error"] =
311+
CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: chatMessage is not a string or malformed" );
307312
return;
308313
}
309314

310-
if ( pServer->SendChatTextToConChannel ( id, jsonChatMessage.toString() ) )
315+
if ( pServer->SendChatTextToConChannel ( id, chatMessage ) )
311316
{
312317
response["error"] = "invalid channel ID";
313318
return;

0 commit comments

Comments
 (0)