From cfab00817a72fabc42b84f4df242eee33c528fba Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Thu, 1 May 2025 11:27:12 +0000 Subject: [PATCH] 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 --- fs/procfs/fs_procfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index c5958fb318..10b564df03 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -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 */