[fpc-pascal] [fcl-web] [jsonrpc] [fpjsonrpc.pp] DoCheckParamArray in TCustomJSONRPCHandler

Michael Anochin anochin at photo-meter.com
Thu Feb 22 14:47:25 CET 2024


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)]);
       end;
     end;  //<< added
end;


More information about the fpc-pascal mailing list