diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-06-15 13:53:30 -0400 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2018-06-15 13:53:30 -0400 |
| commit | f15288993875360dcc2c62b86110ea3c748ee267 (patch) | |
| tree | 2eea1b06e3b2e2df606db4fc5ba5b8826881a874 | |
| parent | 5ce1d71206401622f6f76e54cd524a363aef038a (diff) | |
do not permit mounting over a directory or file with the same name as the mount point
| -rw-r--r-- | shared-module/storage/__init__.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 5b0bbe01e..cc10ebd5a 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -32,6 +32,7 @@ #include "py/mperrno.h" #include "py/obj.h" #include "py/runtime.h" +#include "shared-bindings/os/__init__.h" #include "shared-bindings/storage/__init__.h" STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { @@ -63,8 +64,14 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea args[0] = readonly ? mp_const_true : mp_const_false; args[1] = mp_const_false; // Don't make the file system automatically when mounting. - // call the underlying object to do any mounting operation - mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args); + // Check that there's no file or directory with the same name as the mount point. + nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { + common_hal_os_stat(mount_path); + nlr_pop(); + // Something with the same name exists. + mp_raise_OSError(MP_EEXIST); + } // check that the destination mount point is unused const char *path_out; @@ -78,6 +85,9 @@ void common_hal_storage_mount(mp_obj_t vfs_obj, const char* mount_path, bool rea } } + // call the underlying object to do any mounting operation + mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args); + // Insert the vfs into the mount table by pushing it onto the front of the // mount table. mp_vfs_mount_t **vfsp = &MP_STATE_VM(vfs_mount_table); |
