Skip to content
Snippets Groups Projects
Commit 3f754d33 authored by Sky Dusk's avatar Sky Dusk
Browse files

more formats init

parent c97a3bdb
Branches
No related tags found
1 merge request!2678Remove format whitelist for read only Lua IO and allow more formats.
......@@ -39,13 +39,28 @@
// Allow scripters to write files of these types to SRB2's folder
static const char *whitelist[] = {
".bmp",
".cfg",
".csv",
".dat",
".bin",
".bmp",
".png",
".sav2",
".obj",
".json",
".yaml",
".yml",
".xml",
".csv",
".soc",
".cfg",
".ini",
".txt",
".log",
".md",
".ssg",
".sav2",
};
......@@ -183,7 +198,7 @@ void MakePathDirs(char *path)
}
static int CheckFileName(lua_State *L, const char *filename)
static int CheckFileName(lua_State* L, const char* filename, boolean extensioncheck)
{
int length = strlen(filename);
boolean pass = false;
......@@ -195,12 +210,20 @@ static int CheckFileName(lua_State *L, const char *filename)
return pushresult(L, 0, filename);
}
if (extensioncheck)
{
for (i = 0; i < (sizeof(whitelist) / sizeof(const char*)); i++)
if (!stricmp(&filename[length - strlen(whitelist[i])], whitelist[i]))
{
pass = true;
break;
}
}
else
{
pass = true;
}
if (strstr(filename, "./")
|| strstr(filename, "..") || strchr(filename, ':')
|| filename[0] == '/'
......@@ -218,7 +241,7 @@ static int io_open (lua_State *L) {
const char *mode = luaL_optstring(L, 2, "r");
int checkresult;
checkresult = CheckFileName(L, filename);
checkresult = CheckFileName(L, filename, false);
if (checkresult)
return checkresult;
......@@ -241,7 +264,10 @@ static int io_openlocal (lua_State *L) {
luafiletransfer_t *filetransfer;
int checkresult;
checkresult = CheckFileName(L, filename);
// Decision was made for normal reading (binary + text) to have no whitelist restrictions
boolean readcheck = (strchr(mode, 'w') != NULL) || (strchr(mode, 'a') != NULL) || (strchr(mode, '+') != NULL);
checkresult = CheckFileName(L, filename, readcheck);
if (checkresult)
return checkresult;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment