casaroli opened a new pull request, #21122:
URL: https://github.com/apache/nuttx/pull/21122

   ## Summary
   
   `load_module()` searches `PATH` for a file name without a `/`. An empty name 
has no `/` either, so `exec()`, `posix_spawn()` and `posix_spawnp()` of `""` go 
to the `PATH` search. With `CONFIG_DEBUG_ASSERTIONS`, `envpath_next()` then 
stops the system at `DEBUGASSERT(relpath[0] != '\0')`. Any user program can do 
this.
   
   POSIX specifies `ENOENT` for an empty path or file name. This PR returns 
`-ENOENT` for an empty name before the `PATH` search.
   
   ## Impact
   
   `exec*()`, `posix_spawn()` and `posix_spawnp()` with an empty file name fail 
with `ENOENT` (`posix_spawn*()` return it). Without `CONFIG_DEBUG_ASSERTIONS` 
the old code searched `PATH` for the empty name and failed later; the result is 
now always `ENOENT`. All build modes and architectures. Documentation: no 
change.
   
   ## Testing
   
   Test program `execempty.c`, with `CONFIG_DEBUG_FEATURES` and 
`CONFIG_DEBUG_ASSERTIONS`: `execv("")` and `execvp("")` return -1 with 
`ENOENT`, `posix_spawn()` and `posix_spawnp()` of `""` return `ENOENT`, and the 
program continues.
   
   | | master | this PR |
   |---|---|---|
   | `execempty.c` on `qemu-armv8a:knsh` (kernel, arm64, QEMU with HVF) | 
`Assertion failed : at file: misc/lib_envpath.c:167` at `execv("")`, the system 
stops | all PASS |
   | ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` (with the debug options) 
| status 0 | status 0 |
   
   Build, each OK (master aeab6fbf989 with this change and other small 
independent fixes): `rv-virt:pnsh64` (protected, rv64), `rv-virt:knsh64` 
(kernel, rv64), `mps2-an500:nsh` (flat, armv7-m), `mps2-an500:knsh` (protected, 
armv7-m), `qemu-armv8a:nsh_smp`.
   
   No test in nuttx-apps covers an empty file name.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to