do not permit mounting over a directory or file with the same name as the mount point

This commit is contained in:
Dan Halbert 2018-06-15 13:53:30 -04:00
parent 5ce1d71206
commit f152889938

View File

@ -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);