← index #7389PR #5133
Off-topic · high · value 2.021
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: for implicit declaration of function 'rename'

closedby bfangeropened 2019-09-21updated 2019-10-04
extmod

When compiling with MICROPY_VFS_POSIX enabled on macOS I got:

CC ../../extmod/vfs_posix.c
../../extmod/vfs_posix.c:264:15: error: implicit declaration of function 'rename' is invalid in C99
  [-Werror,-Wimplicit-function-declaration]
    int ret = rename(old_path, new_path);
              ^
1 error generated.
make: *** [build/extmod/vfs_posix.o] Error 1

Adding #include <stdio.h> fixes that error.

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