How to prevent file functions to access files outside game folder?

  c++, file

I’m making a DLL plugin for a game which modders can use in their mods and I’d like to make a function which deletes a file in particular folder. But I want to restrict users from deleting files outside game folder.

alignas(16) char s_strArgTemp[0x4000]; // this is the filepath that modder specifies in the function. I am checking if they specified any file on disk like "C:Windows" and also checking for "..//" which points to a directory back.

        if (strstr(s_strArgTemp, ":")) 
        { 
            *result = -1;
            return true;
        }
        if (strstr(s_strArgTemp, ".."))  
        {
            *result = -1;
            return true; 
        }
        if (strstr(s_strArgTemp, "://"))
        {
            *result = -1;
            return true;
        }
        if (strstr(s_strArgTemp, "..//")) 
        {
            *result = -1;
            return true;
        }

Will this code be enough?

Source: Windows Questions C++

LEAVE A COMMENT