diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-06-16 08:37:52 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-16 08:37:52 -0700 |
| commit | 35ead7bf39d5bf845f547db60109d454ee3e8944 (patch) | |
| tree | f66713aa8c13b4302b1ef8f701b246d2d7992e02 | |
| parent | 92b531d0c3ae9a6422af5f6bb780501bee099a2e (diff) | |
| parent | f15288993875360dcc2c62b86110ea3c748ee267 (diff) | |
Merge pull request #935 from dhalbert/mount_name_clash_check
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); |
