From 097e2289d764950cbd905b024f551742e8920cc0 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 4 Nov 2020 20:18:20 +0100 Subject: [PATCH] doubtfull solution, if he fires requests that require more than two parameters to crash the server it would block him, if 1 pa --- SMJSONAPI/scripting/SMJSONAPI.sp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/SMJSONAPI/scripting/SMJSONAPI.sp b/SMJSONAPI/scripting/SMJSONAPI.sp index f9f6fd7b..7bed5a2f 100644 --- a/SMJSONAPI/scripting/SMJSONAPI.sp +++ b/SMJSONAPI/scripting/SMJSONAPI.sp @@ -147,6 +147,7 @@ static void OnAsyncData(AsyncSocket socket, const char[] data, const int size) static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) { + int parameter_count_verified = 0; static char sMethod[32]; if(jRequest.GetString("method", sMethod, sizeof(sMethod)) < 0) { @@ -174,7 +175,6 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) } g_Client_Subscriber[Client] = Subscriber; } - return Subscriber_HandleRequest(Subscriber, jRequest, jResponse); } else if(StrEqual(sMethod, "function")) @@ -206,7 +206,9 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) } } else + { Call_StartFunction(INVALID_HANDLE, Fun); + } JSONArray jArgsArray = view_as(jRequest.Get("args")); if(jArgsArray == null || !jArgsArray.IsArray) @@ -257,6 +259,7 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) Call_PushArrayEx(aiValues[iValues], jValueArray.Length, SM_PARAM_COPYBACK); iValues += jValueArray.Length; + parameter_count_verified++; } else if(jArrayValue.IsFloat) { @@ -270,6 +273,7 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) Call_PushArrayEx(afValues[fValues], jValueArray.Length, SM_PARAM_COPYBACK); fValues += jValueArray.Length; + parameter_count_verified++; } /*else if(jArrayValue.IsString) { @@ -290,9 +294,15 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) view_as(jArrayValue).GetString(0, sSpecial, sizeof(sSpecial)); if(StrEqual(sSpecial, "NULL_VECTOR")) + { Call_PushArrayEx(NULL_VECTOR, 3, 0); + parameter_count_verified++; + } else if(StrEqual(sSpecial, "NULL_STRING")) + { Call_PushString(NULL_STRING); + parameter_count_verified++; + } else Fail = true; } @@ -323,11 +333,13 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) { aiValues[iValues] = view_as(jValue).Value; Call_PushCell(aiValues[iValues++]); + parameter_count_verified++; } else if(jValue.IsFloat) { afValues[fValues] = view_as(jValue).Value; Call_PushFloat(afValues[fValues++]); + parameter_count_verified++; } else if(jValue.IsString) { @@ -335,6 +347,7 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) JSONString jString = view_as(jValue); jString.GetString(asValues[sValues], sizeof(asValues[])); Call_PushStringEx(asValues[sValues++], sizeof(asValues[]), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + parameter_count_verified++; } else { @@ -355,7 +368,21 @@ static int HandleRequest(int Client, JSONObject jRequest, JSONObject jResponse) } delete jValue; } - + int sm_call_finish_ex_params_size = 2; + if (parameter_count_verified > sm_call_finish_ex_params_size) + { + Call_Cancel(); + delete jArgsArray; + + char sError[128]; + FormatEx(sError, sizeof(sError), "blocking parameterized call %i", parameter_count_verified); + + JSONObject jError = new JSONObject(); + jError.SetString("error", sError); + jResponse.Set("error", jError); + return -1; + } + int Result; static char sException[1024]; int Error = Call_FinishEx(Result, sException, sizeof(sException));