extmod/vfs_posix: Add MICROPY_VFS_POSIX_WRITABLE option.
When this configuration flag is set, VfsPosix instances can be written. Otherwise, they will always be created "read only". This flag is useful when fuzzing micropython: Without VfsPosix, the fuzzing input script cannot be read; but with writable VfsPosix, fuzzing scripts can potentially perform undesired operations on the host filesystem. Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
committed by
Damien George
parent
3c603f7baf
commit
59ee59901b
@@ -137,7 +137,7 @@ static mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, siz
|
|||||||
vstr_add_char(&vfs->root, '/');
|
vstr_add_char(&vfs->root, '/');
|
||||||
}
|
}
|
||||||
vfs->root_len = vfs->root.len;
|
vfs->root_len = vfs->root.len;
|
||||||
vfs->readonly = false;
|
vfs->readonly = !MICROPY_VFS_POSIX_WRITABLE;
|
||||||
|
|
||||||
return MP_OBJ_FROM_PTR(vfs);
|
return MP_OBJ_FROM_PTR(vfs);
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ static mp_obj_t vfs_posix_umount(mp_obj_t self_in) {
|
|||||||
static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_umount_obj, vfs_posix_umount);
|
static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_umount_obj, vfs_posix_umount);
|
||||||
|
|
||||||
static inline bool vfs_posix_is_readonly(mp_obj_vfs_posix_t *self) {
|
static inline bool vfs_posix_is_readonly(mp_obj_vfs_posix_t *self) {
|
||||||
return self->readonly;
|
return !MICROPY_VFS_POSIX_WRITABLE || self->readonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vfs_posix_require_writable(mp_obj_t self_in) {
|
static void vfs_posix_require_writable(mp_obj_t self_in) {
|
||||||
|
|||||||
@@ -1084,6 +1084,11 @@ typedef time_t mp_timestamp_t;
|
|||||||
#define MICROPY_VFS_POSIX (0)
|
#define MICROPY_VFS_POSIX (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Whether to include support for writable POSIX filesystems.
|
||||||
|
#ifndef MICROPY_VFS_POSIX_WRITABLE
|
||||||
|
#define MICROPY_VFS_POSIX_WRITABLE (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Support for VFS FAT component, to mount a FAT filesystem within VFS
|
// Support for VFS FAT component, to mount a FAT filesystem within VFS
|
||||||
#ifndef MICROPY_VFS_FAT
|
#ifndef MICROPY_VFS_FAT
|
||||||
#define MICROPY_VFS_FAT (0)
|
#define MICROPY_VFS_FAT (0)
|
||||||
|
|||||||
Reference in New Issue
Block a user