Some bugs fixed, others not yet.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15250 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-12-24 12:51:08 +00:00
parent ef0117ed3d
commit d53fa016d9
1 changed files with 43 additions and 33 deletions

View File

@ -212,7 +212,6 @@ static msg_t open_dir_absolute(vfs_overlay_driver_c *drvp,
if (drvp->overlaid_drv != NULL) { if (drvp->overlaid_drv != NULL) {
/* Passing the combined path to the overlaid driver.*/ /* Passing the combined path to the overlaid driver.*/
if (err == VFS_RET_SUCCESS) {
err = drvp->overlaid_drv->vmt->open_dir((void *)drvp->overlaid_drv, err = drvp->overlaid_drv->vmt->open_dir((void *)drvp->overlaid_drv,
path, path,
vdnpp); vdnpp);
@ -220,50 +219,61 @@ static msg_t open_dir_absolute(vfs_overlay_driver_c *drvp,
} }
} }
} }
}
while (false); while (false);
return err; return err;
} }
static msg_t drv_set_cwd(void *instance, const char *path) { static msg_t drv_set_cwd(void *instance, const char *path) {
char *buf = NULL;
msg_t ret;
do {
vfs_overlay_driver_c *drvp = (vfs_overlay_driver_c *)instance; vfs_overlay_driver_c *drvp = (vfs_overlay_driver_c *)instance;
vfs_directory_node_c *vdnp; vfs_directory_node_c *vdnp;
msg_t ret; size_t cwdoffset;
/* Taking a path buffer from the pool.*/
buf = vfs_buffer_take();
/* Putting a normalized prefix path into the buffer.*/
ret = vfs_path_normalize(buf, drvp->path_prefix, VFS_CFG_PATHLEN_MAX);
VFS_BREAK_ON_ERROR(ret);
cwdoffset = (size_t)ret;
/* Appending the user CWD. Normalization prevents it to ".."
into the imposed prefix path.*/
ret = vfs_path_normalize(buf + cwdoffset,
path, VFS_CFG_PATHLEN_MAX - (size_t)ret);
VFS_BREAK_ON_ERROR(ret);
/* Trying to access the directory in order to validate the
combined path.*/
ret = open_dir_absolute(drvp, buf, &vdnp);
VFS_BREAK_ON_ERROR(ret);
vdnp->vmt->release((void *)vdnp);
/* One-time allocation of the CWD buffer, this memory is allocated, once, /* One-time allocation of the CWD buffer, this memory is allocated, once,
only if the application uses a CWD, it is never released.*/ only if the application uses a CWD, it is never released.*/
if (drvp->cwd_buffer == NULL) { if (drvp->cwd_buffer == NULL) {
drvp->cwd_buffer = chCoreAlloc(VFS_CFG_PATHLEN_MAX + 1); drvp->cwd_buffer = chCoreAlloc(VFS_CFG_PATHLEN_MAX + 1);
if (drvp->cwd_buffer == NULL) { if (drvp->cwd_buffer == NULL) {
return VFS_RET_ENOMEM; ret = VFS_RET_ENOMEM;
break;
} }
} }
/* Putting a normalized prefix path into the buffer.*/ /* Copying the validated path into the CWD buffer.*/
ret = vfs_path_normalize(drvp->cwd_buffer, strcpy(drvp->cwd_buffer, buf);
drvp->path_prefix, drvp->path_cwd = drvp->cwd_buffer + cwdoffset;
VFS_CFG_PATHLEN_MAX);
VFS_RETURN_ON_ERROR(ret);
/* Pointer to the path just after the imposed prefix.*/ } while (false);
drvp->path_cwd = drvp->cwd_buffer + (size_t)ret;
/* Appending the user CWD. Normalization prevents it to ".."
into the imposed prefix path.*/
ret = vfs_path_normalize(drvp->path_cwd,
path,
VFS_CFG_PATHLEN_MAX - (size_t)ret);
VFS_RETURN_ON_ERROR(ret);
/* Trying to access the directory in order to validate the /* Buffer returned.*/
combined path.*/ vfs_buffer_release(buf);
ret = open_dir_absolute(drvp, drvp->cwd_buffer, &vdnp);
VFS_RETURN_ON_ERROR(ret);
node_dir_release((void *)vdnp); return ret;
return VFS_RET_SUCCESS;
} }
static msg_t drv_get_cwd(void *instance, char *buf, size_t size) { static msg_t drv_get_cwd(void *instance, char *buf, size_t size) {