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
Package registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Shin_Kinr
SRB2
Commits
591b8035
Commit
591b8035
authored
9 years ago
by
wolfs
Browse files
Options
Downloads
Patches
Plain Diff
Limit file write size to 1MB
If the total file size is above 1MB after writing, discard all changes.
parent
e2749465
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/blua/liolib.c
+9
-0
9 additions, 0 deletions
src/blua/liolib.c
with
9 additions
and
0 deletions
src/blua/liolib.c
+
9
−
0
View file @
591b8035
...
...
@@ -26,6 +26,8 @@
#define IO_INPUT 1
#define IO_OUTPUT 2
#define FILELIMIT 1024*1024 // Size limit for reading/writing files
static
const
char
*
const
fnames
[]
=
{
"input"
,
"output"
};
static
const
char
*
whitelist
[]
=
{
// Allow scripters to write files of these types to SRB2's folder
...
...
@@ -437,6 +439,7 @@ static int io_readline (lua_State *L) {
static
int
g_write
(
lua_State
*
L
,
FILE
*
f
,
int
arg
)
{
int
nargs
=
lua_gettop
(
L
)
-
1
;
int
status
=
1
;
size_t
count
;
for
(;
nargs
--
;
arg
++
)
{
if
(
lua_type
(
L
,
arg
)
==
LUA_TNUMBER
)
{
/* optimization: could be done exactly as for strings */
...
...
@@ -446,6 +449,12 @@ static int g_write (lua_State *L, FILE *f, int arg) {
else
{
size_t
l
;
const
char
*
s
=
luaL_checklstring
(
L
,
arg
,
&
l
);
count
+=
l
;
if
(
ftell
(
f
)
+
l
>
FILELIMIT
)
{
luaL_error
(
L
,
"write limit bypassed in file. Changes have been discarded."
);
break
;
}
status
=
status
&&
(
fwrite
(
s
,
sizeof
(
char
),
l
,
f
)
==
l
);
}
}
...
...
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