Rewrite CommandLine creation in Dos.Exec function to avoid problems when ComLine is 255 characters long

git-svn-id: trunk@34015 -
This commit is contained in:
pierre 2016-06-21 10:13:41 +00:00
parent 3253711e95
commit 7efce7f121

View File

@ -280,9 +280,11 @@ var
SI: TStartupInfo; SI: TStartupInfo;
PI: TProcessInformation; PI: TProcessInformation;
l : Longint; l : Longint;
CommandLine : array[0..511] of char; { Maximum length of both short string is
AppParam : array[0..255] of char; 2x255 = 510, plus possibly two double-quotes,
pathlocal : string; two spaces and the final #0, makes 515 chars }
CommandLine : array[0..515] of char;
has_no_double_quote : boolean;
begin begin
DosError:=0; DosError:=0;
FillChar(SI, SizeOf(SI), 0); FillChar(SI, SizeOf(SI), 0);
@ -293,18 +295,31 @@ begin
do it if there are already double quotes, since Win32 does not do it if there are already double quotes, since Win32 does not
like double quotes which are duplicated! like double quotes which are duplicated!
} }
if pos('"',path) = 0 then has_no_double_quote:=pos('"',path)=0;
pathlocal:='"'+path+'"' if has_no_double_quote then
begin
CommandLine[0]:='"';
l:=1;
end
else else
pathlocal := path; l:=0;
Move(Pathlocal[1],CommandLine,length(Pathlocal)); Move(Path[1],CommandLine[l],length(Path));
l:=l+length(Path);
AppParam[0]:=' '; if has_no_double_quote then
AppParam[1]:=' '; begin
Move(ComLine[1],AppParam[2],length(Comline)); CommandLine[l]:='"';
AppParam[Length(ComLine)+2]:=#0; inc(l);
{ concatenate both pathnames } end;
Move(Appparam[0],CommandLine[length(Pathlocal)],strlen(Appparam)+1); { Add two spaces }
CommandLine[l]:=' ';
inc(l);
CommandLine[l]:=' ';
inc(l);
{ Add comline string }
Move(ComLine[1],CommandLine[l],length(Comline));
l:=l+length(ComLine);
{ Terminate string }
CommandLine[l]:=#0;
if not CreateProcess(nil, PChar(@CommandLine), if not CreateProcess(nil, PChar(@CommandLine),
Nil, Nil, ExecInheritsHandles,$20, Nil, Nil, SI, PI) then Nil, Nil, ExecInheritsHandles,$20, Nil, Nil, SI, PI) then
begin begin