mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 18:59:11 +02:00
Improve targ1a and targ1b to really check content of args passed to called executable
git-svn-id: trunk@34067 -
This commit is contained in:
parent
67503ad692
commit
360f2734eb
@ -9,7 +9,8 @@ type
|
|||||||
TMemArray = array [0..MAX_SIZE div SIZE_INC] of pointer;
|
TMemArray = array [0..MAX_SIZE div SIZE_INC] of pointer;
|
||||||
|
|
||||||
var
|
var
|
||||||
i : longint;
|
i, length_arg2 : longint;
|
||||||
|
err :word;
|
||||||
MemArray : TMemArray;
|
MemArray : TMemArray;
|
||||||
|
|
||||||
function Size(i: longint) : longint;
|
function Size(i: longint) : longint;
|
||||||
@ -23,10 +24,22 @@ begin
|
|||||||
begin
|
begin
|
||||||
GetMem(MemArray[i],Size(i));
|
GetMem(MemArray[i],Size(i));
|
||||||
end;
|
end;
|
||||||
for i:=0 to MAX_SIZE div SIZE_INC do
|
for i:=1 to MAX_SIZE div SIZE_INC do
|
||||||
begin
|
begin
|
||||||
FreeMem(MemArray[i],Size(i));
|
FreeMem(MemArray[i],Size(i));
|
||||||
end;
|
end;
|
||||||
Writeln(stderr,'Everything is fine');
|
i:=length(paramstr(1));
|
||||||
|
Writeln(stderr,'Everthing is fine, arg1 length=',i);
|
||||||
|
val(paramstr(1),length_arg2,err);
|
||||||
|
if err=0 then
|
||||||
|
begin
|
||||||
|
i:=length(paramstr(2));
|
||||||
|
if (i<>length_arg2) then
|
||||||
|
begin
|
||||||
|
Writeln('Length of arg2 is ',i,' not ',length_arg2);
|
||||||
|
halt(1);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Writeln('length of arg2 OK: ',length_arg2);
|
||||||
|
end;
|
||||||
end.
|
end.
|
||||||
|
@ -11,6 +11,10 @@ program create_startup_test_crash;
|
|||||||
{$ifdef go32v2}
|
{$ifdef go32v2}
|
||||||
{$define HasExeSuffix}
|
{$define HasExeSuffix}
|
||||||
{$endif}
|
{$endif}
|
||||||
|
{$ifdef msdos}
|
||||||
|
{$define HasExeSuffix}
|
||||||
|
{$define DosMaxArg}
|
||||||
|
{$endif}
|
||||||
{$ifdef win32}
|
{$ifdef win32}
|
||||||
{$define HasExeSuffix}
|
{$define HasExeSuffix}
|
||||||
{$endif}
|
{$endif}
|
||||||
@ -61,28 +65,50 @@ const
|
|||||||
const
|
const
|
||||||
MAX = 255;
|
MAX = 255;
|
||||||
|
|
||||||
|
{$ifdef DosMaxArg}
|
||||||
|
OK_L = 126;
|
||||||
|
{$else not DosMaxArg}
|
||||||
|
OK_L = 200;
|
||||||
|
{$endif not DosMaxArg}
|
||||||
|
|
||||||
var
|
var
|
||||||
cmd,
|
cmd,
|
||||||
arg : string;
|
arg,arg2_length_string,args : string;
|
||||||
i, first_wrong : longint;
|
i, first, first_wrong,arg2_length,total_length : longint;
|
||||||
const
|
const
|
||||||
Everything_ok : boolean = true;
|
Everything_ok : boolean = true;
|
||||||
begin
|
begin
|
||||||
cmd:=Prefix+'targ1a'+ExeSuffix;
|
cmd:=Prefix+'targ1a'+ExeSuffix;
|
||||||
arg:='';
|
arg:='';
|
||||||
first_wrong:=-1;
|
first_wrong:=-1;
|
||||||
for i:=0 to MAX do
|
if paramcount>0 then
|
||||||
begin
|
begin
|
||||||
Writeln(stderr,'Going to call "',cmd,'" with arg = "',arg,'"');
|
val(paramstr(1),first);
|
||||||
Writeln(stderr,'arg length =',length(arg));
|
for i:=1 to first do
|
||||||
Exec(cmd,arg);
|
arg:=arg+'a';
|
||||||
|
end
|
||||||
|
else
|
||||||
|
first:=0;
|
||||||
|
for i:=first to MAX - 4 { 4 chars needed for first arg and space } do
|
||||||
|
begin
|
||||||
|
arg2_length:=length(arg);
|
||||||
|
Writeln(stderr,'Going to call "',cmd,'" with arg2 = "',arg,'"');
|
||||||
|
Writeln(stderr,'arg2 length =',arg2_length);
|
||||||
|
str(arg2_length, arg2_length_string);
|
||||||
|
args:=arg2_length_string+' '+arg;
|
||||||
|
total_length:=length(args);
|
||||||
|
Writeln(stderr,'Length of all args=',total_length);
|
||||||
|
Exec(cmd,args);
|
||||||
if (DosExitCode<>0) or (DosError<>0) then
|
if (DosExitCode<>0) or (DosError<>0) then
|
||||||
begin
|
begin
|
||||||
Writeln(stderr,'Crash detected, DosError=', DosError);
|
if DosError<>0 then
|
||||||
Writeln(stderr,'DosExitCode=',DosExitCode);
|
Writeln(stderr,'Dos.Exec error detected, DosError=', DosError)
|
||||||
|
else
|
||||||
|
Writeln(stderr,'Error running targ1a, DosExitCode=',DosExitCode);
|
||||||
if first_wrong=-1 then
|
if first_wrong=-1 then
|
||||||
first_wrong:=i;
|
first_wrong:=total_length;
|
||||||
Everything_ok := false;
|
Everything_ok := false;
|
||||||
|
break;
|
||||||
end;
|
end;
|
||||||
arg:=arg+'a';
|
arg:=arg+'a';
|
||||||
end;
|
end;
|
||||||
@ -94,7 +120,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
Writeln(stderr,'Test fails: Memory corruption occurs');
|
Writeln(stderr,'Test fails: Memory corruption occurs');
|
||||||
Writeln(stderr,'First arg length where error appears is ',first_wrong);
|
Writeln(stderr,'First arg length where error appears is ',first_wrong);
|
||||||
if first_wrong<100 then
|
if first_wrong<OK_L then
|
||||||
RunError(1)
|
RunError(1)
|
||||||
else
|
else
|
||||||
Writeln(stderr,'Warning: when using Dos.Exec, arg length must be smaller than ',first_wrong);
|
Writeln(stderr,'Warning: when using Dos.Exec, arg length must be smaller than ',first_wrong);
|
||||||
|
Loading…
Reference in New Issue
Block a user