Преглед изворни кода

Merged revisions 12941,12946-12952 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r12941 | joost | 2009-03-21 18:36:35 +0100 (Sat, 21 Mar 2009) | 1 line

* Fixed a security issue. Do not try to run an executable named fpc in the current directory, but only search for it in the path
........
r12946 | joost | 2009-03-22 10:35:48 +0100 (Sun, 22 Mar 2009) | 1 line

* Added ImplicitCurrentDir : Boolean = True parameter to FileSearch
........
r12947 | joost | 2009-03-22 11:02:24 +0100 (Sun, 22 Mar 2009) | 1 line

* Implemented function ExeSearch
........
r12948 | joost | 2009-03-22 11:03:03 +0100 (Sun, 22 Mar 2009) | 1 line

* Use ExeSearch instead of FileSearch to find compiler executable
........
r12949 | joost | 2009-03-22 11:04:04 +0100 (Sun, 22 Mar 2009) | 1 line

* Use ExeSearch instead of FileSearch to find fpc executable
........
r12950 | joost | 2009-03-22 11:04:46 +0100 (Sun, 22 Mar 2009) | 1 line

* Use ExeSearch instead of FileSearch to find command executable
........
r12951 | joost | 2009-03-22 11:05:25 +0100 (Sun, 22 Mar 2009) | 1 line

* Use ExeSearch instead of FileSearch to find process executable
........
r12952 | joost | 2009-03-22 11:08:24 +0100 (Sun, 22 Mar 2009) | 1 line

* Use ExeSearch instead of FileSearch to find compiler/command executable
........

git-svn-id: tags/release_2_2_4@12968 -

joost пре 16 година
родитељ
комит
9331a2e959

+ 1 - 1
compiler/utils/fpc.pp

@@ -98,7 +98,7 @@ program fpc;
        end
       else
        begin
-         path:=FileSearch(ppcbin,getenvironmentvariable('PATH'));
+         path:=ExeSearch(ppcbin,getenvironmentvariable('PATH'));
          if path<>'' then
           begin
             ppcbin:=path;

+ 1 - 1
packages/fcl-process/src/unix/process.inc

@@ -269,7 +269,7 @@ begin
           end;
 
         if not FileExists(PName) then begin
-          FoundName := FileSearch(Pname,fpgetenv('PATH'));
+          FoundName := ExeSearch(Pname,fpgetenv('PATH'));
           if FoundName<>'' then
             PName:=FoundName
           else

+ 2 - 2
packages/fpmkunit/src/fpmkunit.pp

@@ -3231,7 +3231,7 @@ begin
             O:=Substitute(C.Options,['SOURCE',C.SourceFile,'DEST',C.DestFile]);
             Cmd:=C.Command;
             If (ExtractFilePath(Cmd)='') then
-              Cmd:=FileSearch(Cmd,GetEnvironmentvariable('PATH'));
+              Cmd:=ExeSearch(Cmd,GetEnvironmentvariable('PATH'));
             ExecuteCommand(Cmd,O,C.IgnoreResult);
             If Assigned(C.AfterCommand) then
               C.AfterCommand(C);
@@ -3583,7 +3583,7 @@ begin
     FCompiler:=Defaults.Compiler;
     If (ExtractFilePath(FCompiler)='') then
       begin
-      S:=FileSearch(FCompiler,GetEnvironmentVariable('PATH'));
+      S:=ExeSearch(FCompiler,GetEnvironmentVariable('PATH'));
       If (S<>'') then
          FCompiler:=S;
       end;

+ 2 - 1
rtl/objpas/sysutils/filutilh.inc

@@ -93,7 +93,8 @@ Function FileGetAttr (Const FileName : String) : Longint;
 Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
 Function DeleteFile (Const FileName : String) : Boolean;
 Function RenameFile (Const OldName, NewName : String) : Boolean;
-Function FileSearch (Const Name, DirList : String) : String;
+Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean = True) : String;
+Function ExeSearch  (Const Name, DirList : String) : String;
 Function FileIsReadOnly(const FileName: String): Boolean;
 
 Function GetFileHandle(var f : File):Longint;

+ 16 - 4
rtl/objpas/sysutils/sysutils.inc

@@ -18,18 +18,18 @@
   { variant error codes }
   {$i varerror.inc}
 
-    Function FileSearch (Const Name, DirList : String) : String;
+    Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean = True) : String;
     Var
       I : longint;
       Temp : String;
 
     begin
-      // Start with checking the file in the current directory
       Result:=Name;
       temp:=SetDirSeparators(DirList);
+      // Start with checking the file in the current directory
+      If ImplicitCurrentDir and (Result <> '') and FileExists(Result) Then
+        exit;
       while True do begin
-        If (Result <> '') and FileExists(Result) Then
-          exit;
         If Temp = '' then
           Break; // No more directories to search - fail
         I:=pos(PathSeparator,Temp);
@@ -45,10 +45,22 @@
           end;
         If Result<>'' then
           Result:=IncludeTrailingPathDelimiter(Result)+name;
+        If (Result <> '') and FileExists(Result) Then
+          exit;
       end;
       result:='';
     end;
 
+    Function ExeSearch (Const Name, DirList : String) : String;
+
+    begin
+    {$ifdef unix}
+      Result := FileSearch(Name, DirList, False);
+    {$else unix}
+      Result := FileSearch(Name, DirList, True);
+    {$endif unix}
+    end;
+
   {$ifndef OS_FILEISREADONLY}
   Function FileIsReadOnly(const FileName: String): Boolean;
 

+ 2 - 2
utils/fppkg/fpmkunitsrc.inc

@@ -3616,7 +3616,7 @@ const fpmkunitsrc : array[0..599,1..240] of char=(
   'DEST'#039',C.DestFile',']);'#010+
   '            Cmd:=C.Command;'#010+
   '            If (ExtractFilePath(Cmd)='#039#039') then'#010+
-  '              Cmd:=FileSearch(Cmd,GetEnvironmentvariable('#039'PATH'#039+
+  '              Cmd:=ExeSearch(Cmd,GetEnvironmentvariable('#039'PATH'#039+
   '));'#010+
   '            ExecuteCommand(Cmd,O,C.IgnoreResult);'#010+
   '            If Assigned(C.AfterCommand) then'#010,
@@ -4000,7 +4000,7 @@ const fpmkunitsrc : array[0..599,1..240] of char=(
   '    FCompiler:=Defaults.Compiler;'#010+
   '    If (ExtractFilePath(FCompiler)='#039#039') then'#010+
   '      begin'#010+
-  '      S:=FileSearch(FCompiler,GetEnvironmen','tVariable('#039'PATH'#039')'+
+  '      S:=ExeSearch(FCompiler,GetEnvironmen','tVariable('#039'PATH'#039')'+
   ');'#010+
   '      If (S<>'#039#039') then'#010+
   '         FCompiler:=S;'#010+

+ 2 - 1
utils/fppkg/pkgoptions.pp

@@ -432,11 +432,12 @@ end;
 
 
 procedure TCompilerOptions.InitCompilerDefaults;
+
 var
   infoSL : TStringList;
 begin
   FConfigVersion:=CurrentConfigVersion;
-  FCompiler:=FileSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
+  FCompiler:=ExeSearch('fpc'+ExeExt,GetEnvironmentVariable('PATH'));
   if FCompiler='' then
     Raise EPackagerError.Create(SErrMissingFPC);
   // Detect compiler version/target from -i option