fs/procfs: Improve subdirectory recognition

This patch fixes https://github.com/apache/nuttx/issues/16237, where
cd'ing to a non-directory prefix of a procfs entry would succeed.

Signed-off-by: Pip Cet <pipcet@protonmail.com>
This commit is contained in:
Pip Cet 2025-05-01 11:27:12 +00:00 committed by Alan C. Assis
parent 43b29a0547
commit cfab00817a

View file

@ -740,7 +740,8 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
/* Test for a sub-string match (e.g. "ls /proc/fs") */
else if (strncmp(g_procfs_entries[x].pathpattern, relpath,
len) == 0)
len) == 0 &&
g_procfs_entries[x].pathpattern[len] == '/')
{
FAR struct procfs_level1_s *level1;
@ -1166,7 +1167,8 @@ static int procfs_stat(FAR struct inode *mountpt, FAR const char *relpath,
/* Test for an internal subdirectory stat */
else if (strncmp(g_procfs_entries[x].pathpattern, relpath,
len) == 0)
len) == 0 &&
g_procfs_entries[x].pathpattern[len] == '/')
{
/* It's an internal subdirectory */