From 778f7f00cbd5bad2cb3c667a1caada30f25f7a9a Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Fri, 17 Jul 2026 16:00:00 +0800 Subject: [PATCH] fs/hostfs: Fix long root path construction hostfs_mkpath() appends a relative path to the configured host root with strlcat(). The third argument to strlcat() is the total destination buffer size, not the remaining free space. Passing pathlen - strlen(path) makes the effective limit shrink after a long host root has already been copied. With a sufficiently long root, a valid relative path can be dropped or truncated, so operations under the mount point may resolve to the host root instead of the requested child path. Pass the full destination buffer size and let strlcat() account for the current string length internally. The companion examples/hostfs_longpath app validates this regression by mounting hostfs with a long host root, writing a probe file below the mount point, and reading it back. The old size argument drops the relative component in that scenario; this fix preserves it. Assisted-by: Claude:Claude-Fable-5 Signed-off-by: Lingao Meng --- fs/hostfs/hostfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index 53143a6d309..697a1215486 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -230,7 +230,7 @@ static void hostfs_mkpath(FAR struct hostfs_mountpt_s *fs, if (depth >= 0) { - strlcat(path, &relpath[first], pathlen - strlen(path)); + strlcat(path, &relpath[first], pathlen); } }