You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2026/10/18 11:36:28 UTC

(nuttx) branch master updated (2808c2fa99d -> 8f8448337d9)

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

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


    from 2808c2fa99d libs/libc/netdb: Reject empty labels in dn_comp().
     new 220ae585cee libs/libc/misc: Support AT_EMPTY_PATH in fstatat().
     new 8f8448337d9 libs/libc/misc: Return ENOENT for an empty path in the *at() functions.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 libs/libc/misc/lib_fstatat.c     | 16 +++++++++++++++-
 libs/libc/misc/lib_getfullpath.c | 10 ++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)


(nuttx) 01/02: libs/libc/misc: Support AT_EMPTY_PATH in fstatat().

Posted by ac...@apache.org.
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 220ae585cee87e7ee4aee1825decfb01af119674
Author: Marco Casaroli <ma...@gmail.com>
AuthorDate: Sat Oct 17 19:58:31 2026 +0200

    libs/libc/misc: Support AT_EMPTY_PATH in fstatat().
    
    fstatat() ignored the AT_EMPTY_PATH flag.  An empty path then worked
    only by accident: lib_getfullpath() joined the path of dirfd (or the
    current directory) with the empty string.
    
    fstatat() now handles AT_EMPTY_PATH with an empty path.  It calls
    fstat() on dirfd, or uses the current directory when dirfd is
    AT_FDCWD.  This is the Linux behavior.  It also works for a dirfd
    that is not a directory.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <ma...@gmail.com>
---
 libs/libc/misc/lib_fstatat.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/libs/libc/misc/lib_fstatat.c b/libs/libc/misc/lib_fstatat.c
index 4a1ded9773b..e91d3768533 100644
--- a/libs/libc/misc/lib_fstatat.c
+++ b/libs/libc/misc/lib_fstatat.c
@@ -52,11 +52,15 @@
  *
  *   If pathname is absolute, then dirfd is ignored.
  *
+ *   If pathname is an empty string and flags contains AT_EMPTY_PATH, then
+ *   the call operates on the file referred to by dirfd (like fstat()).  If
+ *   dirfd is AT_FDCWD, the call operates on the current working directory.
+ *
  * Input Parameters:
  *   dirfd - The file descriptor of directory.
  *   path  - A pointer to the path.
  *   buf   - The buf to get file status.
- *   flags - Ignored.
+ *   flags - AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH are supported.
  *
  * Returned Value:
  *   Return zero on success, or -1 if an error occurred (in which case,
@@ -70,6 +74,16 @@ int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf,
   FAR char *fullpath;
   int ret;
 
+  if (path != NULL && path[0] == '\0' && (flags & AT_EMPTY_PATH) != 0)
+    {
+      if (dirfd != AT_FDCWD)
+        {
+          return fstat(dirfd, buf);
+        }
+
+      path = ".";
+    }
+
   fullpath = lib_get_pathbuffer();
   if (fullpath == NULL)
     {


(nuttx) 02/02: libs/libc/misc: Return ENOENT for an empty path in the *at() functions.

Posted by ac...@apache.org.
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 <ma...@gmail.com>
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 <ma...@gmail.com>
---
 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. */