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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3b9dd6eae11 binfmt: Search PATH only for a file name without a slash.
3b9dd6eae11 is described below

commit 3b9dd6eae11286cc0e8c528e29577c27673bf10d
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Oct 9 13:26:03 2026 +0200

    binfmt: Search PATH only for a file name without a slash.
    
    load_module() searched PATH for every name that did not start with '/'.
    A path relative to the current directory, such as "./hello" or
    "bin/hello", was joined to each PATH directory, so "./hello" ran
    /system/bin/hello when it existed instead of the hello in the current
    directory, and failed with ENOENT when it did not.
    
    POSIX searches PATH only for a name that contains no '/'; any other
    name is a path, used as it is.  Do the same: the VFS resolves a
    relative path against the current working directory.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 binfmt/binfmt_loadmodule.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/binfmt/binfmt_loadmodule.c b/binfmt/binfmt_loadmodule.c
index 06d56c0c9b5..57f7c073194 100644
--- a/binfmt/binfmt_loadmodule.c
+++ b/binfmt/binfmt_loadmodule.c
@@ -29,6 +29,7 @@
 #include <sched.h>
 #include <nuttx/debug.h>
 #include <errno.h>
+#include <string.h>
 
 #include <nuttx/lib/lib.h>
 #include <nuttx/envpath.h>
@@ -89,8 +90,8 @@ static int load_default_priority(FAR struct binary_s *bin)
  *
  * Description:
  *   Load a module into memory, bind it to an exported symbol table, and
- *   prep the module for execution.  filename is known to be an absolute
- *   path to the file to be loaded.
+ *   prep the module for execution.  filename is the path to the file to
+ *   be loaded: absolute, or relative to the current working directory.
  *
  * Returned Value:
  *   Zero (OK) is returned on success; a negated errno value is returned on
@@ -184,12 +185,14 @@ int load_module(FAR struct binary_s *bin, FAR const char 
*filename,
           return ret;
         }
 
-      /* Were we given a relative path?  Or an absolute path to the file to
-       * be loaded?  Absolute paths start with '/'.
+      /* A bare file name (no '/') is searched for in PATH.  Any other path
+       * is used as given: an absolute path, or a path relative to the
+       * current working directory, as POSIX specifies for a name that
+       * contains a '/'.
        */
 
 #ifdef CONFIG_LIBC_ENVPATH
-      if (filename[0] != '/')
+      if (strchr(filename, '/') == NULL)
         {
           FAR char *fullpath;
           ENVPATH_HANDLE handle;
@@ -229,8 +232,8 @@ int load_module(FAR struct binary_s *bin, FAR const char 
*filename,
       else
 #endif
         {
-          /* We already have the one and only absolute path to the file to
-           * be loaded.
+          /* We already have the one and only path to the file to be
+           * loaded.
            */
 
           ret = load_absmodule(bin, filename, exports, nexports);

Reply via email to