Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
3f754d33
Commit
3f754d33
authored
1 month ago
by
Sky Dusk
Browse files
Options
Downloads
Patches
Plain Diff
more formats init
parent
c97a3bdb
Branches
Branches containing commit
No related tags found
1 merge request
!2678
Remove format whitelist for read only Lua IO and allow more formats.
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/blua/liolib.c
+40
-14
40 additions, 14 deletions
src/blua/liolib.c
with
40 additions
and
14 deletions
src/blua/liolib.c
+
40
−
14
View file @
3f754d33
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment