This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8f8448337d9beb736b34608c16b240e9c8b23a85
Author: Marco Casaroli <[email protected]>
AuthorDate: Sat Oct 17 19:58:48 2026 +0200

    libs/libc/misc: Return ENOENT for an empty path in the *at() functions.
    
    POSIX says that an empty path names no file.  The *at() functions
    must fail with ENOENT for an empty path.  lib_getfullpath() joined the
    path of dirfd (or $PWD for AT_FDCWD) with the empty string, so the
    empty path named the directory.  Thus faccessat(AT_FDCWD, "", X_OK, 0)
    and fstatat(AT_FDCWD, "", &st, 0) succeeded, and a shell test such
    as [ -x "" ] was true.
    
    lib_getfullpath() now returns -ENOENT for an empty path.  This is the
    same error that stat(""), access("") and open("") already give.
    fstatat() with AT_EMPTY_PATH handles the empty path before it calls
    lib_getfullpath(), so it is not changed.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 libs/libc/misc/lib_getfullpath.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libs/libc/misc/lib_getfullpath.c b/libs/libc/misc/lib_getfullpath.c
index b7f930301fd..05cbd256e43 100644
--- a/libs/libc/misc/lib_getfullpath.c
+++ b/libs/libc/misc/lib_getfullpath.c
@@ -42,6 +42,10 @@
  * Description:
  *   Given the directory path from dirfd.
  *
+ * Returned Value:
+ *   Zero on success.  -EINVAL if path or fullpath is NULL.  -ENOENT if
+ *   path is an empty string.
+ *
  ****************************************************************************/
 
 int lib_getfullpath(int dirfd, FAR const char *path,
@@ -51,6 +55,12 @@ int lib_getfullpath(int dirfd, FAR const char *path,
     {
       return -EINVAL;
     }
+  else if (path[0] == '\0')
+    {
+      /* An empty path names no file.  It does not name dirfd. */
+
+      return -ENOENT;
+    }
   else if (path[0] == '/')
     {
       /* The path is absolute, then dirfd is ignored. */

Reply via email to