Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
c3e34289
Commit
c3e34289
authored
5 years ago
by
Michael Huebler
Committed by
schneider
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added blacklist for write access for certain file names.
parent
c7494640
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!162
Added blacklist for write access for certain file names.
Pipeline
#2747
passed
5 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pycardium/modules/fat_file.c
+34
-4
34 additions, 4 deletions
pycardium/modules/fat_file.c
with
34 additions
and
4 deletions
pycardium/modules/fat_file.c
+
34
−
4
View file @
c3e34289
/*
* based on micropyt
o
hn/ports/unix/file.c
* based on micropyth
o
n/ports/unix/file.c
*/
#include
<stdio.h>
...
...
@@ -12,6 +12,24 @@
#include
"epicardium.h"
#include
<strings.h>
bool
filename_restricted
(
const
char
*
fname
)
{
// files that cannot be opened in write modes
const
char
*
const
forbidden_files
[]
=
{
"cardio.bin"
,
"menu.py"
,
"main.py"
,
"cardio.cfg"
};
for
(
int
i
=
0
;
i
<
sizeof
(
forbidden_files
)
/
sizeof
(
forbidden_files
[
0
]);
i
++
)
{
if
(
strcasecmp
(
fname
,
forbidden_files
[
i
])
==
0
)
{
return
true
;
}
}
return
false
;
}
extern
const
mp_obj_type_t
mp_type_textio
;
#if MICROPY_PY_IO_FILEIO
extern
const
mp_obj_type_t
mp_type_fileio
;
...
...
@@ -120,8 +138,9 @@ STATIC const mp_arg_t file_open_args[] = {
STATIC
mp_obj_t
file_open
(
const
mp_obj_type_t
*
type
,
mp_arg_val_t
*
args
)
{
const
char
*
modeString
=
mp_obj_str_get_str
(
args
[
1
].
u_obj
);
const
char
*
mode_s
=
modeString
;
bool
potentially_critical_access
=
false
;
const
char
*
modeString
=
mp_obj_str_get_str
(
args
[
1
].
u_obj
);
const
char
*
mode_s
=
modeString
;
// modes r w x a + are handled on epicardium side, binary / text
// is relevant for python type so look for these here
while
(
*
mode_s
)
{
...
...
@@ -134,6 +153,12 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args)
case
't'
:
type
=
&
mp_type_textio
;
break
;
case
'w'
:
case
'x'
:
case
'a'
:
case
'+'
:
potentially_critical_access
=
true
;
break
;
}
}
...
...
@@ -141,7 +166,12 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args)
o
->
base
.
type
=
type
;
const
char
*
fname
=
mp_obj_str_get_str
(
args
[
0
].
u_obj
);
int
res
=
epic_file_open
(
fname
,
modeString
);
if
(
potentially_critical_access
&&
filename_restricted
(
fname
))
{
mp_raise_OSError
(
-
EPERM
);
}
int
res
=
epic_file_open
(
fname
,
modeString
);
if
(
res
<
0
)
{
m_del_obj
(
fat_py_file_obj_t
,
o
);
mp_raise_OSError
(
-
res
);
...
...
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