From 0a518b65d149322ab247139dd6c3cb8bca1a4401 Mon Sep 17 00:00:00 2001 From: James Crook Date: Mon, 20 Feb 2017 12:17:16 +0000 Subject: [PATCH] Don't follow symlinks in RecursivelyEnumerate Projects will only have symlinks in them if they have been tampered with, and then following the links, especially when doing CleanDir(), would be dangerous. So don't. Improved comments, otherwise it isn't clear that CleanDir is needed on Windows and Linux, not just Mac. It is deleting whole subdirs, not just .DS_Store files. --- src/DirManager.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/DirManager.cpp b/src/DirManager.cpp index 45875fc11bea..d1fdb0bab6a0 100644 --- a/src/DirManager.cpp +++ b/src/DirManager.cpp @@ -147,6 +147,9 @@ wxMemorySize GetFreeMemory() // subdirs of subdirs. Files in the passed-in directory will not be // enumerated. Also, the passed-in directory is the last entry added // to the list. +// JKC: Using flag wxDIR_NO_FOLLOW to NOT follow symbolic links. +// Directories and files inside a project should never be symbolic +// links, so if we find one, do not follow it. static int RecursivelyEnumerate(wxString dirPath, wxArrayString& filePathArray, // output: all files in dirPath tree wxString dirspec, @@ -163,7 +166,7 @@ static int RecursivelyEnumerate(wxString dirPath, wxString name; if (bFiles){ - cont= dir.GetFirst(&name, dirspec, wxDIR_FILES | wxDIR_HIDDEN); + cont= dir.GetFirst(&name, dirspec, wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW); while ( cont ){ wxString filepath = dirPath + wxFILE_SEP_PATH + name; @@ -178,7 +181,7 @@ static int RecursivelyEnumerate(wxString dirPath, } } - cont= dir.GetFirst(&name, dirspec, wxDIR_DIRS); + cont= dir.GetFirst(&name, dirspec, wxDIR_DIRS | wxDIR_NO_FOLLOW); while ( cont ){ wxString subdirPath = dirPath + wxFILE_SEP_PATH + name; count += RecursivelyEnumerate( @@ -412,12 +415,13 @@ void DirManager::CleanDir( wxArrayString filePathArray, dirPathArray; - // Subtract 1 because we don't want to DELETE the global temp directory, - // which this will find and list last. int countFiles = RecursivelyEnumerate(path, filePathArray, dirSpec, true, false); int countDirs = RecursivelyEnumerate(path, dirPathArray, dirSpec, false, true); + + // Subtract 1 because we don't want to DELETE the global temp directory, + // which this will find and list last. if (!removeTop) { // Remove the globaltemp itself from the array --countDirs; @@ -559,7 +563,7 @@ bool DirManager::SetProject(wxString& newProjPath, wxString& newProjName, const // folders have been moved away already, but: // to fix bug1567 on Mac, we need to find the extraneous .DS_Store files // that we didn't put there, but that Finder may insert into the folders, - // and mercilessly remove them too. + // and mercilessly remove them, in addition to removing the directories. CleanDir( cleanupLoc1, wxEmptyString, _("Cleaning up cache directories"), true);