Skip to content

Commit cc65036

Browse files
committed
vfs_posix: Add MICROPY_VFS_POSIX_READONLY.
When this configuration flag is set, VfsPosix instances will always be created "read only". This flag is when fuzzing micropython: Without VfsPosix, the fuzzing input script cannot be read; but with writable VfsPosix, fuzzing scripts can access and potentially damage the host filesystem. Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent db9371c commit cc65036

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

extmod/vfs_posix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, siz
137137
vstr_add_char(&vfs->root, '/');
138138
}
139139
vfs->root_len = vfs->root.len;
140-
vfs->readonly = false;
140+
vfs->readonly = MICROPY_VFS_POSIX_READONLY;
141141

142142
return MP_OBJ_FROM_PTR(vfs);
143143
}
@@ -161,7 +161,7 @@ static mp_obj_t vfs_posix_umount(mp_obj_t self_in) {
161161
static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_umount_obj, vfs_posix_umount);
162162

163163
static bool vfs_posix_is_readonly(mp_obj_vfs_posix_t *self) {
164-
return self->readonly;
164+
return MICROPY_VFS_POSIX_READONLY || self->readonly;
165165
}
166166

167167
static void vfs_posix_require_writable(mp_obj_t self_in) {

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,11 @@ typedef time_t mp_timestamp_t;
10841084
#define MICROPY_VFS_POSIX (0)
10851085
#endif
10861086

1087+
// When enabled, the POSIX VFS is always read-only.
1088+
#ifndef MICROPY_VFS_POSIX_READONLY
1089+
#define MICROPY_VFS_POSIX_READONLY (0)
1090+
#endif
1091+
10871092
// Support for VFS FAT component, to mount a FAT filesystem within VFS
10881093
#ifndef MICROPY_VFS_FAT
10891094
#define MICROPY_VFS_FAT (0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy