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 <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2026-07-17 16:00:00 +08:00
parent 2a934fbfba
commit abc545ee95

View file

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