From 2139f1e53e76cfaec433918c7b081a340c0e466b Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Fri, 15 Dec 2023 15:09:50 -0800 Subject: [PATCH] fs: fuse: Avoid possible buffer overflow Checks path's size before copying it to local variable. Signed-off-by: Flavio Ceolin (cherry picked from commit 3267bdc4b78bd773b59498c686b4914b3b1c0596) --- subsys/fs/fuse_fs_access.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/subsys/fs/fuse_fs_access.c b/subsys/fs/fuse_fs_access.c index e39416f91cf78d..d3df397842f9aa 100644 --- a/subsys/fs/fuse_fs_access.c +++ b/subsys/fs/fuse_fs_access.c @@ -65,8 +65,15 @@ static void release_file_handle(size_t handle) static bool is_mount_point(const char *path) { char dir_path[PATH_MAX]; + size_t len; - sprintf(dir_path, "%s", path); + len = strlen(path); + if (len >= sizeof(dir_path)) { + return false; + } + + memcpy(dir_path, path, len); + dir_path[len] = '\0'; return strcmp(dirname(dir_path), "/") == 0; }