This repository was archived by the owner on Oct 28, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,44 @@ STATIC uint8_t mp_task_heap[MP_TASK_HEAP_SIZE];
76
76
extern uint32_t reset_cause ;
77
77
extern bool in_safe_mode ;
78
78
79
+ static const char * import_blacklist [] = {
80
+ "/lib/json" ,
81
+ "/lib/os" ,
82
+ "/lib/socket" ,
83
+ "/lib/struct" ,
84
+ "/lib/time" ,
85
+ };
86
+
87
+ mp_import_stat_t
88
+ mp_import_stat (const char * path ) {
89
+ if (in_safe_mode ) {
90
+ // be more strict in which modules we would like to load
91
+ if (strncmp (path , "/lib/" , 5 ) != 0 ) {
92
+ return MP_IMPORT_STAT_NO_EXIST ;
93
+ }
94
+
95
+ /* check blacklist */
96
+ int i ;
97
+ for (i = 0 ; i < sizeof (import_blacklist )/sizeof (const char * ); i ++ ) {
98
+ if (strcmp (path , import_blacklist [i ]) == 0 ) {
99
+ return MP_IMPORT_STAT_NO_EXIST ;
100
+ }
101
+ }
102
+
103
+ const char * x = index (& path [5 ], '/' );
104
+ if (x == NULL ) {
105
+ // only allow directories
106
+ mp_import_stat_t res = mp_vfs_import_stat (path );
107
+ if (res != MP_IMPORT_STAT_DIR ) {
108
+ return MP_IMPORT_STAT_NO_EXIST ;
109
+ }
110
+ return res ;
111
+ }
112
+ }
113
+
114
+ return mp_vfs_import_stat (path );
115
+ }
116
+
79
117
void mp_task (void * pvParameter ) {
80
118
volatile uint32_t sp = (uint32_t )get_sp ();
81
119
#if MICROPY_PY_THREAD
Original file line number Diff line number Diff line change 159
159
#define MICROPY_SDMMC_USE_DRIVER (1)
160
160
#define MICROPY_SDMMC_SHOW_INFO (1)
161
161
162
- // use vfs's functions for import stat and builtin open
163
- #define mp_import_stat mp_vfs_import_stat
162
+ // use vfs's functions for builtin open
164
163
#define mp_builtin_open mp_vfs_open
165
164
#define mp_builtin_open_obj mp_vfs_open_obj
166
165
You can’t perform that action at this time.
0 commit comments