On Thu, 22 Feb 2024, Michael Anochin via fpc-pascal wrote:
Hello,
the TCustomJSONRPCHandler.DoCheckParamArray in fpjsonrpc.pp causes an
exception with the message "List index (0) out of bounds".
This happens, for example, if ParamArray is empty and there are not
required parameter in ParamDef (required not set). In that case
ParamArray[i] not exists, so Param:=ParamArray[i] raises "index out of
bounds" exception.
I would like to check this before assignment, may be like this
procedure TCustomJSONRPCHandler.DoCheckParamArray(const ParamArray:
TJSONArray);
var
I : Integer;
Param: TJSONData;
Def : TJSONParamDef;
begin
for I:=0 to ParamDefs.Count-1 do
begin
Def:=ParamDefs[i];
if I>=ParamArray.Count then
if ParamDefs[i].Required then
JSONRPCParamError(SErrParamsRequiredParamNotFound,[def.Name]);
//Check ParamArray.Count first
if (I<ParamArray.Count) then begin //<< added
Param:=ParamArray[i];
// jtUnkown accepts all data types
if (def.DataType<>jtUnknown) and not
(Param.JSONType=def.DataType) then
JSONRPCParamError(SErrParamsDataTypeMismatch,[def.Name,JSONTypeName(def.DataType),JSONTypeName(Param.JSONType)]);
As it happens, I was working on adding some things to fpjsonrpc,
so I fixed this issue by putting the code in an else branch.
I pushed that change.
Michael.
_______________________________________________
fpc-pascal maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal