Improve targ1a and targ1b to really check content of args passed to called executable

git-svn-id: trunk@34067 -
This commit is contained in:
pierre 2016-07-04 21:03:40 +00:00
parent 67503ad692
commit 360f2734eb
2 changed files with 53 additions and 14 deletions

View File

@ -9,7 +9,8 @@ type
TMemArray = array [0..MAX_SIZE div SIZE_INC] of pointer;
var
i : longint;
i, length_arg2 : longint;
err :word;
MemArray : TMemArray;
function Size(i: longint) : longint;
@ -23,10 +24,22 @@ begin
begin
GetMem(MemArray[i],Size(i));
end;
for i:=0 to MAX_SIZE div SIZE_INC do
for i:=1 to MAX_SIZE div SIZE_INC do
begin
FreeMem(MemArray[i],Size(i));
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.

View File

@ -11,6 +11,10 @@ program create_startup_test_crash;
{$ifdef go32v2}
{$define HasExeSuffix}
{$endif}
{$ifdef msdos}
{$define HasExeSuffix}
{$define DosMaxArg}
{$endif}
{$ifdef win32}
{$define HasExeSuffix}
{$endif}
@ -61,28 +65,50 @@ const
const
MAX = 255;
{$ifdef DosMaxArg}
OK_L = 126;
{$else not DosMaxArg}
OK_L = 200;
{$endif not DosMaxArg}
var
cmd,
arg : string;
i, first_wrong : longint;
arg,arg2_length_string,args : string;
i, first, first_wrong,arg2_length,total_length : longint;
const
Everything_ok : boolean = true;
begin
cmd:=Prefix+'targ1a'+ExeSuffix;
arg:='';
first_wrong:=-1;
for i:=0 to MAX do
if paramcount>0 then
begin
Writeln(stderr,'Going to call "',cmd,'" with arg = "',arg,'"');
Writeln(stderr,'arg length =',length(arg));
Exec(cmd,arg);
val(paramstr(1),first);
for i:=1 to first do
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
begin
Writeln(stderr,'Crash detected, DosError=', DosError);
Writeln(stderr,'DosExitCode=',DosExitCode);
if DosError<>0 then
Writeln(stderr,'Dos.Exec error detected, DosError=', DosError)
else
Writeln(stderr,'Error running targ1a, DosExitCode=',DosExitCode);
if first_wrong=-1 then
first_wrong:=i;
first_wrong:=total_length;
Everything_ok := false;
break;
end;
arg:=arg+'a';
end;
@ -94,7 +120,7 @@ begin
begin
Writeln(stderr,'Test fails: Memory corruption occurs');
Writeln(stderr,'First arg length where error appears is ',first_wrong);
if first_wrong<100 then
if first_wrong<OK_L then
RunError(1)
else
Writeln(stderr,'Warning: when using Dos.Exec, arg length must be smaller than ',first_wrong);