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
63e60314
Commit
63e60314
authored
5 years ago
by
swym
Browse files
Options
Downloads
Patches
Plain Diff
pycardium: check file-blacklist in os.unlink and os.rename, too
parent
d29f8f95
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!167
pycardium: check file-blacklist in os.unlink and os.rename, too
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pycardium/modules/fat_file.c
+3
-20
3 additions, 20 deletions
pycardium/modules/fat_file.c
pycardium/modules/os.c
+31
-3
31 additions, 3 deletions
pycardium/modules/os.c
pycardium/modules/os.h
+6
-0
6 additions, 0 deletions
pycardium/modules/os.h
with
40 additions
and
23 deletions
pycardium/modules/fat_file.c
+
3
−
20
View file @
63e60314
...
@@ -11,24 +11,7 @@
...
@@ -11,24 +11,7 @@
#include
"py/mperrno.h"
#include
"py/mperrno.h"
#include
"epicardium.h"
#include
"epicardium.h"
#include
"os.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
;
extern
const
mp_obj_type_t
mp_type_textio
;
#if MICROPY_PY_IO_FILEIO
#if MICROPY_PY_IO_FILEIO
...
@@ -167,8 +150,8 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args)
...
@@ -167,8 +150,8 @@ STATIC mp_obj_t file_open(const mp_obj_type_t *type, mp_arg_val_t *args)
const
char
*
fname
=
mp_obj_str_get_str
(
args
[
0
].
u_obj
);
const
char
*
fname
=
mp_obj_str_get_str
(
args
[
0
].
u_obj
);
if
(
potentially_critical_access
&&
filename_restricted
(
fname
))
{
if
(
potentially_critical_access
&&
pycrd_
filename_restricted
(
fname
))
{
mp_raise_OSError
(
-
E
PERM
);
mp_raise_OSError
(
-
E
ACCES
);
}
}
int
res
=
epic_file_open
(
fname
,
modeString
);
int
res
=
epic_file_open
(
fname
,
modeString
);
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/os.c
+
31
−
3
View file @
63e60314
...
@@ -4,6 +4,27 @@
...
@@ -4,6 +4,27 @@
#include
"py/runtime.h"
#include
"py/runtime.h"
#include
<string.h>
#include
<string.h>
#include
<strings.h>
#include
<stdbool.h>
#include
"os.h"
bool
pycrd_filename_restricted
(
const
char
*
fname
)
{
// files that cannot be opened in write modes
const
char
*
const
forbidden_files
[]
=
{
"card10.bin"
,
"menu.py"
,
"main.py"
,
"card10.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
;
}
static
mp_obj_t
mp_os_exit
(
size_t
n_args
,
const
mp_obj_t
*
args
)
static
mp_obj_t
mp_os_exit
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
{
...
@@ -89,7 +110,10 @@ static MP_DEFINE_CONST_FUN_OBJ_1(listdir_obj, mp_os_listdir);
...
@@ -89,7 +110,10 @@ static MP_DEFINE_CONST_FUN_OBJ_1(listdir_obj, mp_os_listdir);
static
mp_obj_t
mp_os_unlink
(
mp_obj_t
py_path
)
static
mp_obj_t
mp_os_unlink
(
mp_obj_t
py_path
)
{
{
const
char
*
path
=
mp_obj_str_get_str
(
py_path
);
const
char
*
path
=
mp_obj_str_get_str
(
py_path
);
int
rc
=
epic_file_unlink
(
path
);
if
(
pycrd_filename_restricted
(
path
))
{
mp_raise_OSError
(
-
EACCES
);
}
int
rc
=
epic_file_unlink
(
path
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
{
mp_raise_OSError
(
-
rc
);
mp_raise_OSError
(
-
rc
);
...
@@ -114,7 +138,11 @@ static mp_obj_t mp_os_rename(mp_obj_t py_oldp, mp_obj_t py_newp)
...
@@ -114,7 +138,11 @@ static mp_obj_t mp_os_rename(mp_obj_t py_oldp, mp_obj_t py_newp)
{
{
const
char
*
oldp
=
mp_obj_str_get_str
(
py_oldp
);
const
char
*
oldp
=
mp_obj_str_get_str
(
py_oldp
);
const
char
*
newp
=
mp_obj_str_get_str
(
py_newp
);
const
char
*
newp
=
mp_obj_str_get_str
(
py_newp
);
int
rc
=
epic_file_rename
(
oldp
,
newp
);
if
(
pycrd_filename_restricted
(
oldp
)
||
pycrd_filename_restricted
(
newp
))
{
mp_raise_OSError
(
-
EACCES
);
}
int
rc
=
epic_file_rename
(
oldp
,
newp
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
{
mp_raise_OSError
(
-
rc
);
mp_raise_OSError
(
-
rc
);
...
@@ -141,7 +169,7 @@ static mp_obj_t mp_os_urandom(mp_obj_t size_in)
...
@@ -141,7 +169,7 @@ static mp_obj_t mp_os_urandom(mp_obj_t size_in)
vstr_t
vstr
;
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
size
);
vstr_init_len
(
&
vstr
,
size
);
epic_trng_read
((
uint8_t
*
)
vstr
.
buf
,
size
);
epic_trng_read
((
uint8_t
*
)
vstr
.
buf
,
size
);
return
mp_obj_new_str_from_vstr
(
&
mp_type_bytes
,
&
vstr
);
return
mp_obj_new_str_from_vstr
(
&
mp_type_bytes
,
&
vstr
);
}
}
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/os.h
0 → 100644
+
6
−
0
View file @
63e60314
#ifndef PYCARDIUM_MODULES_OS_H_INCLUDED
#define PYCARDIUM_MODULES_OS_H_INCLUDED
bool
pycrd_filename_restricted
(
const
char
*
fname
);
#endif//PYCARDIUM_MODULES_OS_H_INCLUDED
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