← index #7389PR #17713
Related · high · value 0.646
QUERY · ISSUE

vfs_posix_rename old_path points to the same as new_path

openby bhcuong2008opened 2021-06-12updated 2021-06-13
extmod

Hi,

During my investigation of vfs posix MPY 1.15, I found that there is issue in logic as following, although I have not tested it yet. Please refer to file https://github.com/micropython/micropython/blob/master/extmod/vfs_posix.c, line 271.

At first, old_path points to root buffer, member of mp_obj_vfs_posix_t .
After that, new_path also points to root buffer with new value "new_path_in". At this point, both old_path and new_path points to the same string in root buffer with the latest value "new_path_in".

So when executing rename(old_path, new_path) will be failed.

STATIC mp_obj_t vfs_posix_rename(mp_obj_t self_in, mp_obj_t old_path_in, mp_obj_t new_path_in) {
    mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
    const char *old_path = vfs_posix_get_path_str(self, old_path_in);
    const char *new_path = vfs_posix_get_path_str(self, new_path_in);
    MP_THREAD_GIL_EXIT();
    int ret = rename(old_path, new_path);
    MP_THREAD_GIL_ENTER();
    if (ret != 0) {
        mp_raise_OSError(errno);
    }
    return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_rename_obj, vfs_posix_rename);
CANDIDATE · PULL REQUEST

Fix incomplete implementation of readonly for VfsPosix

closedby jepleropened 2025-07-19updated 2025-07-24
extmod

Summary

I noticed that operations such as unlink could be performed on a nominally read-only VfsPosix.

Fix all these operations, and then add a compile-time configuration option MICROPY_VFS_POSIX_WRITABLE. Disabling this option ensures that a VfsPosix instance is ALWAYS read-only. This may be useful when fuzzing micropython, which can otherwise make modifications to the host filesystem.

Testing

I added a new test for VfsPosix read-only mode.

Trade-offs and Alternatives

Initially, I structured the test as an importable module so that other filesystems could potentially re-use the same test code; however, most(all?) other filesystems are based on block devices, and I don't think they have the same problems with needing to add readonly checks in each code path since they just ensure the block write function cannot be called. It also turns out ci_webassembly_run_tests failed due to inability to import the auxiliary file, so I went with the one-file implementation after all.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied