mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-26 12:44:09 +02:00
Merged revision(s) 51033-51034 #6faa4e893c-#6faa4e893c, 51038-51039 #10e166f60e-#10e166f60e, 51041 #35b30db335 from trunk:
LazUtils: Prevent CopyDirTree copying to a subdirectory of source. Issue #28841. ........ LazUtils: Use trimmed paths for comparing sub-dir in CopyDirTree. Fix return value. Issue #28841. ........ LazUtils: Better fix "Prevent CopyDirTree copying to a subdirectory of source." Issue #28841. ........ LazUtils: Fix r51038 #10e166f60e for Issue #28841. ........ LazUtils: CopyDirTree: better readable Boolean expression. ........ git-svn-id: branches/fixes_1_6@51078 -
This commit is contained in:
parent
beecbb57ad
commit
015fc4f7b7
@ -696,6 +696,8 @@ end;
|
||||
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
|
||||
var
|
||||
Searcher: TCopyDirTree;
|
||||
RelPath: String;
|
||||
B: Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
Searcher:=TCopyDirTree.Create;
|
||||
@ -704,12 +706,17 @@ begin
|
||||
Flags:=Flags+[cffCreateDestDirectory];
|
||||
Searcher.FFlags:=Flags;
|
||||
Searcher.FCopyFailedCount:=0;
|
||||
Searcher.FSourceDir:=SetDirSeparators(SourceDir);
|
||||
Searcher.FTargetDir:=SetDirSeparators(TargetDir);
|
||||
Searcher.FSourceDir:=LazFileUtils.TrimFilename(SetDirSeparators(SourceDir));
|
||||
Searcher.FTargetDir:=LazFileUtils.TrimFilename(SetDirSeparators(TargetDir));
|
||||
|
||||
// Don't even try to copy to a subdirectory of SourceDir.
|
||||
B := TryCreateRelativePath(LazFileUtils.ExpandFilenameUtf8(Searcher.FSourceDir),
|
||||
LazFileUtils.ExpandFilenameUtf8(Searcher.FTargetDir), False, True, RelPath);
|
||||
if B and ((Copy(RelPath,1,2) = '..') or (RelPath = '')) then Exit;
|
||||
|
||||
Searcher.Search(SourceDir);
|
||||
Result:=True;
|
||||
finally
|
||||
Result:=Searcher.FCopyFailedCount=0;
|
||||
finally
|
||||
Searcher.Free;
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user