Prevent access to /Save/Preferences.ini from lua

Directly writing to the file would circumvent preference protections,
compromising security.
This commit is contained in:
Martin Natano
2022-05-07 23:53:58 +02:00
parent b9ebbd32a9
commit d54bc6857f
4 changed files with 71 additions and 59 deletions
+12 -1
View File
@@ -8,6 +8,7 @@
#include "global.h"
#include "RageFileBasic.h"
#include "RageFile.h"
#include "RageLog.h"
#include "RageUtil.h"
#include "RageFileDriver.h"
@@ -351,7 +352,17 @@ public:
static int Open( T* p, lua_State *L )
{
lua_pushboolean( L, p->Open( SArg(1), IArg(2) ) );
const RString path = SArg(1);
int mode = IArg(2);
if ((mode & RageFile::WRITE) && FILEMAN->IsPathProtected(path))
{
LOG->Warn("Writing to %s is not allowed", path.c_str());
lua_pushboolean(L, false);
return 1;
}
lua_pushboolean( L, p->Open(path, mode) );
return 1;
}