- fixed path traversal on POSIX platforms

This commit is contained in:
alexey.lysiuk 2020-01-29 11:41:23 +02:00
parent 93fb98413e
commit 9dd3213393
4 changed files with 7 additions and 4 deletions

View File

@ -162,7 +162,7 @@ void CollectSubdirectories(TArray<FString> &searchpath, const char *dirmatch)
{
findstate_t findstate;
void* handle;
if ((handle = I_FindFirst(AbsPath + "/*.*", &findstate)) != (void*)-1)
if ((handle = I_FindFirst(AbsPath + "/*", &findstate)) != (void*)-1)
{
do
{

View File

@ -180,6 +180,7 @@ void* I_FindFirst(const char* const filespec, findstate_t* const fileinfo)
{
pattern = slash+1;
dir = FString(filespec, slash - filespec + 1);
fileinfo->path = dir;
}
else
{
@ -234,7 +235,7 @@ int I_FindAttr(findstate_t* const fileinfo)
dirent* const ent = fileinfo->namelist[fileinfo->current];
bool isdir;
if (DirEntryExists(ent->d_name, &isdir))
if (DirEntryExists(fileinfo->path + ent->d_name, &isdir))
{
return isdir ? FA_DIREC : 0;
}

View File

@ -73,9 +73,10 @@ bool I_SetCursor(FTexture *);
struct findstate_t
{
private:
int count;
FString path;
struct dirent **namelist;
int current;
int count;
friend void *I_FindFirst(const char *filespec, findstate_t *fileinfo);
friend int I_FindNext(void *handle, findstate_t *fileinfo);

View File

@ -304,6 +304,7 @@ void *I_FindFirst (const char *filespec, findstate_t *fileinfo)
{
pattern = slash+1;
dir = FString(filespec, slash-filespec+1);
fileinfo->path = dir;
}
else
{
@ -350,7 +351,7 @@ int I_FindAttr(findstate_t* const fileinfo)
dirent* const ent = fileinfo->namelist[fileinfo->current];
bool isdir;
if (DirEntryExists(ent->d_name, &isdir))
if (DirEntryExists(fileinfo->path + ent->d_name, &isdir))
{
return isdir ? FA_DIREC : 0;
}