Skip to content

Commit

Permalink
protect against recursive symbolic links when scanning directories [p…
Browse files Browse the repository at this point in the history
…=2813993]
  • Loading branch information
cfillion committed Oct 9, 2024
1 parent 539b524 commit 5f9ad46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion SnM/SnM_Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ bool GenerateFilename(const char* _dir, const char* _name, const char* _ext, cha
return false;
}

bool IsDirNoRecurse(const WDL_DirScan &ds)
{
enum { IsDir = 1, IsDirSymlink = 2, IsRecurDirSymLink = 4 };
return (ds.GetCurrentIsDirectory() & (IsDir | IsDirSymlink)) != 0;
}

// fills a list of filenames matching extensions defined in _filterList
// _filterList: file extensions without null separators, ex: "*.ext1 *.ext2" ("*" == all files)
// note: it is up to the caller to free _files (use WDL_PtrList_DeleteOnDestroy)
Expand All @@ -468,7 +474,7 @@ void ScanFiles(WDL_PtrList<WDL_String>* _files, const char* _initDir, const char
if (!strcmp(curFn, ".") || !strcmp(curFn, ".."))
continue;

if (ds.GetCurrentIsDirectory())
if (IsDirNoRecurse(ds))
{
if (_subdirs) {
ds.GetCurrentFullFN(&fn);
Expand Down
1 change: 1 addition & 0 deletions SnM/SnM_Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ bool TranscodeFileToFile64(const char* _outFn, const char* _inFn);
WDL_HeapBuf* TranscodeStr64ToHeapBuf(const char* _str64);
bool GenerateFilename(const char* _dir, const char* _name, const char* _ext, char* _updatedFn, int _updatedSz);
void ScanFiles(WDL_PtrList<WDL_String>* _files, const char* _initDir, const char* _filterList, bool _subdirs);
bool IsDirNoRecurse(const WDL_DirScan &);
void StringToExtensionConfig(WDL_FastString* _str, ProjectStateContext* _ctx);
void ExtensionConfigToString(WDL_FastString* _str, ProjectStateContext* _ctx);

Expand Down
2 changes: 1 addition & 1 deletion Xenakios/XenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int SearchDirectory(vector<string> &refvecFiles, const char* cDir, const char* c
WDL_String foundFile;
ds.GetCurrentFullFN(&foundFile);
lstrcpyn(g_CurrentScanFile, foundFile.Get(), 1024);
if (bSubdirs && ds.GetCurrentIsDirectory())
if (bSubdirs && IsDirNoRecurse(ds))
{
found += SearchDirectory(refvecFiles, foundFile.Get(), cExt, true);
}
Expand Down

0 comments on commit 5f9ad46

Please sign in to comment.