Bladeren bron

* check paramstr argument for negative values, resolves #39410

florian 3 jaren geleden
bovenliggende
commit
7baf2461f0
8 gewijzigde bestanden met toevoegingen van 39 en 35 verwijderingen
  1. 1 1
      rtl/aix/system.pp
  2. 17 17
      rtl/beos/system.pp
  3. 1 1
      rtl/bsd/system.pp
  4. 2 2
      rtl/haiku/system.pp
  5. 1 1
      rtl/linux/system.pp
  6. 9 7
      rtl/nds/system.pp
  7. 1 1
      rtl/solaris/system.pp
  8. 7 5
      rtl/wii/system.pp

+ 1 - 1
rtl/aix/system.pp

@@ -83,7 +83,7 @@ function paramstr(l: longint) : string;
  begin
    { stricly conforming POSIX applications  }
    { have the executing filename as argv[0] }
-     if (l < argc) then
+     if ( l>= 0) and (l < argc) then
        paramstr:=strpas(argv[l])
      else
        paramstr:='';

+ 17 - 17
rtl/beos/system.pp

@@ -10,7 +10,7 @@ interface
 
 {$I sysunixh.inc}
 
-  
+
 type
   THeapPointer = ^pointer;
 var
@@ -93,7 +93,7 @@ begin
   WriteLn('SBRK');
   Str(size, s);
   WriteLn('size : ' + s);
-  if (myheapsize+size)<=myheaprealsize then 
+  if (myheapsize+size)<=myheaprealsize then
   begin
     Sbrk:=pointer(heapstart+myheapsize);
     myheapsize:=myheapsize+size;
@@ -102,7 +102,7 @@ begin
   newsize:=myheapsize+size;
   newrealsize:=(newsize and $FFFFF000)+$1000;
   case resize_area(heap_handle,newrealsize) of
-    B_OK : 
+    B_OK :
       begin
         WriteLn('B_OK');
         Sbrk:=pointer(heapstart+myheapsize);
@@ -140,7 +140,7 @@ function sys_resize_area (handle:cardinal; size:longint):longint; cdecl; externa
   WriteLn('sbrk');
   Str(size, s);
   WriteLn('size : ' + s);
-  if (myheapsize+size)<=myheaprealsize then 
+  if (myheapsize+size)<=myheaprealsize then
   begin
     Sbrk:=heapstart+myheapsize;
     myheapsize:=myheapsize+size;
@@ -148,7 +148,7 @@ function sys_resize_area (handle:cardinal; size:longint):longint; cdecl; externa
   end;
   newsize:=myheapsize+size;
   newrealsize:=(newsize and $FFFFF000)+$1000;
-  if sys_resize_area(heap_handle,newrealsize+$1000)=0 then 
+  if sys_resize_area(heap_handle,newrealsize+$1000)=0 then
   begin
     WriteLn('sys_resize_area OK');
     Str(longint(newrealsize), s);
@@ -160,15 +160,15 @@ function sys_resize_area (handle:cardinal; size:longint):longint; cdecl; externa
     Str(myheapsize, s);
     WriteLn('Total : ' + s);
     WriteLn('Before fillchar');
-    WriteLn('sbrk : $' + Hexstr(longint(heapstart+myheapsize), 8));        
+    WriteLn('sbrk : $' + Hexstr(longint(heapstart+myheapsize), 8));
     Sbrk:=heapstart+myheapsize;
-    FillChar(sbrk^, size, #0);    
+    FillChar(sbrk^, size, #0);
     WriteLn('EndFillChar');
     WriteLn('sbrk : $' + Hexstr(longint(sbrk), 8));
 //    ReadLn(s);
     myheapsize:=newsize;
     Str({longint(heapstartpointer) +} myheapsize, s);
-    WriteLn('Total : ' + s);    
+    WriteLn('Total : ' + s);
     myheaprealsize:=newrealsize;
     exit;
   end
@@ -265,14 +265,14 @@ var
   s: string;
   s1: string;
 begin
-   
+
   { stricly conforming POSIX applications  }
   { have the executing filename as argv[0] }
   if l = 0 then
   begin
     paramstr := execpathstr;
   end
-  else if (l < argc) then
+  else if (l > 0) and (l < argc) then
   begin
     paramstr:=strpas(argv[l]);
   end
@@ -389,7 +389,7 @@ begin
   heapstart:=nil;
   heapstartpointer := nil;
   heapstartpointer := Sbrk2(4096*1);
-{$IFDEF FPC_USE_LIBC}  
+{$IFDEF FPC_USE_LIBC}
 //  heap_handle := create_area('fpcheap',heapstart,0,myheaprealsize,0,3);//!!
 {$ELSE}
 //  debugger('tata'#0);
@@ -403,8 +403,8 @@ begin
 
   FillChar(heapstartpointer^, myheaprealsize, #0);
 //  WriteLn('EndFillChar');
-//    WriteLn('P : $' + Hexstr(longint(heapstartpointer), 8));        
-//    WriteLn('heapstart : $' + Hexstr(longint(heapstartpointer^), 8));        
+//    WriteLn('P : $' + Hexstr(longint(heapstartpointer), 8));
+//    WriteLn('heapstart : $' + Hexstr(longint(heapstartpointer^), 8));
   heapstart := heapstartpointer;
 {$ENDIF}
 //  WriteLn('before InitHeap');
@@ -415,10 +415,10 @@ begin
 //    B_ERROR : WriteLn('B_ERROR');
 //  else
 //    begin
-//      WriteLn('ok');  
-//      WriteLn('P : $' + Hexstr(longint(heapstartpointer), 8));        
-//      WriteLn('heapstart : $' + Hexstr(longint(heapstartpointer^), 8));       
-//      if heap_handle>0 then 
+//      WriteLn('ok');
+//      WriteLn('P : $' + Hexstr(longint(heapstartpointer), 8));
+//      WriteLn('heapstart : $' + Hexstr(longint(heapstartpointer^), 8));
+//      if heap_handle>0 then
 //      begin
         InitHeap;
 //      end;

+ 1 - 1
rtl/bsd/system.pp

@@ -159,7 +159,7 @@ function paramstr(l: longint) : string;
 //       paramstr := execpathstr;
 //     end
 //   else
-     if (l < argc) then
+     if (l >= 0) and (l < argc) then
        paramstr:=strpas(argv[l])
      else
        paramstr:='';

+ 2 - 2
rtl/haiku/system.pp

@@ -146,7 +146,7 @@ begin
   begin
     paramstr := execpathstr;
   end
-  else if (l < argc) then
+  else if (l > 0) and (l < argc) then
   begin
     paramstr:=strpas(argv[l]);
   end
@@ -193,7 +193,7 @@ end;
 {$i sighnd.inc}
 
 procedure set_signal_stack(ptr : pointer; size : size_t); cdecl; external 'root' name 'set_signal_stack';
-function sigaltstack(const stack : pstack_t; oldStack : pstack_t) : integer; cdecl; external 'root' name 'sigaltstack'; 
+function sigaltstack(const stack : pstack_t; oldStack : pstack_t) : integer; cdecl; external 'root' name 'sigaltstack';
 
 type
   {$PACKRECORDS C}

+ 1 - 1
rtl/linux/system.pp

@@ -459,7 +459,7 @@ function paramstr(l: longint) : string;
          SysInitExecPath;
        paramstr := execpathstr;
      end
-   else if (l < argc) then
+   else if (l > 0) and (l < argc) then
      paramstr:=strpas(argv[l])
    else
      paramstr:='';

+ 9 - 7
rtl/nds/system.pp

@@ -25,7 +25,7 @@ interface
 {$define FPC_HAS_FEATURE_FILEIO}
 {$define FPC_HAS_FEATURE_THREADING}
 
-{$define CPUARM_HAS_UMULL} 
+{$define CPUARM_HAS_UMULL}
 {$ifdef FPC_HAS_INTERNAL_BSR}
   {$define CPUARM_HAS_CLZ}
 {$endif def FPC_HAS_INTERNAL_BSR}
@@ -76,18 +76,18 @@ var
 //  errno: integer;
   fake_heap_end: ^byte; cvar; external;
   irq_vector: integer; external name '__irq_vector';
-  
+
 function get_cmdline:Pchar;
 
 property cmdline:Pchar read get_cmdline;
 
 implementation
 
-const 
+const
   calculated_cmdline: Pchar = nil;
   { System limits, POSIX value in parentheses, used for buffer and stack allocation }
   ARG_MAX  = 65536;   {4096}  { Maximum number of argument size     }
-  PATH_MAX = 1024;    {255}   { Maximum number of bytes in pathname }  
+  PATH_MAX = 1024;    {255}   { Maximum number of bytes in pathname }
 
 {$define fpc_softfpu_implementation}
 {$i softfpu.pp}
@@ -159,8 +159,10 @@ function paramstr(l: longint) : string;
      begin
        paramstr := execpathstr;
      end
-   else
-     paramstr:=strpas(argv[l]);
+   else (l > 0) and (l < argc) then
+     paramstr := strpas(argv[l])
+  else
+    paramstr := '';
  end;
 
 {*****************************************************************************
@@ -264,7 +266,7 @@ begin
   SysInitExceptions;
 
   SetupCmdLine;
-  
+
 {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
   { Setup stdin, stdout and stderr }
   SysInitStdIO;

+ 1 - 1
rtl/solaris/system.pp

@@ -115,7 +115,7 @@ function paramstr(l: longint) : string;
 //       paramstr := execpathstr;
 //     end
 //   else
-     if (l < argc) then
+     if (l >= 0) and (l < argc) then
        paramstr:=strpas(argv[l])
      else
        paramstr:='';

+ 7 - 5
rtl/wii/system.pp

@@ -62,18 +62,18 @@ var
   argv: PPChar;
   envp: PPChar;
 //  errno: integer;
-  
+
 function get_cmdline:Pchar;
 
 property cmdline:Pchar read get_cmdline;
 
 implementation
 
-const 
+const
   calculated_cmdline: Pchar = nil;
   { System limits, POSIX value in parentheses, used for buffer and stack allocation }
   ARG_MAX  = 65536;   {4096}  { Maximum number of argument size     }
-  PATH_MAX = 1024;    {255}   { Maximum number of bytes in pathname }  
+  PATH_MAX = 1024;    {255}   { Maximum number of bytes in pathname }
 
 
 {$i system.inc}
@@ -128,8 +128,10 @@ function paramstr(l: longint) : string;
      begin
        paramstr := execpathstr;
      end
+   else (l > 0) and ( l < argc ) then
+     paramstr:=strpas(argv[l])
    else
-     paramstr:=strpas(argv[l]);
+     paramstr:='';
  end;
 
 {*****************************************************************************
@@ -234,7 +236,7 @@ begin
   SysInitExceptions;
   initunicodestringmanager;
   SetupCmdLine;
-  
+
 {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
   { Setup stdin, stdout and stderr }
   SysInitStdIO;