fs: fuse: Fix possible buffer overflow

Ensure that the path in fuse_fs_access_readdir does not overflow
the local buffer.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2023-09-25 23:19:13 -07:00 committed by Fabio Baltieri
commit 3521c95c2f

View file

@ -176,9 +176,15 @@ static int fuse_fs_access_readdir(const char *path, void *buf,
* directory but FUSE strips the trailing slashes from
* directory names so add it back.
*/
char mount_path[PATH_MAX];
char mount_path[PATH_MAX] = {0};
size_t len = strlen(path);
sprintf(mount_path, "%s/", path);
if (len >= (PATH_MAX - 2)) {
return -ENOMEM;
}
memcpy(mount_path, path, len)
mount_path[len] = '/';
err = fs_opendir(&dir, mount_path);
} else {
err = fs_opendir(&dir, path);