casaroli opened a new pull request, #20569: URL: https://github.com/apache/nuttx/pull/20569
## Summary The startup code of ELF programs calls `main(argc, argv)`. A program that declares `int main(int argc, char *argv[], char *envp[])`, a common Unix extension, reads a random value as `envp` and crashes when it walks it. This PR makes crt0 pass `environ` as the third argument (`NULL` with `CONFIG_DISABLE_ENVIRON`), on arm, arm64, risc-v, x86_64 and xtensa. ## Impact ELF programs linked with the NuttX `crt0`, in any build mode, whose `main()` takes `envp`. A program with a two-argument `main()` is not affected. ## Testing `qemu-armv8a:knsh` in QEMU 11. The test program was built outside the tree against the export package. It prints `envp`, after `set FOO hello` in NSH. Before: ``` envpmain: envp 0xc00012d0 environ 0xc00056d8 arm64_fatal_handler: Segmentation fault in envpmain (PID 6: envpmain) ``` After: ``` envpmain: envp 0xc00056d8 environ 0xc00056d8 envpmain: envp[0] = PWD=/ envpmain: envp[1] = PATH=/system/bin envpmain: envp[2] = FOO=hello envpmain: 3 entries ``` Kernel builds with `-Wno-cpp -Werror`, each followed by `make export` and the apps `make import`: `qemu-armv8a:knsh`, `imx93-evk:knsh`, `qemu-armv7a:knsh`, `sabre-6quad:netknsh`, `sama5d4-ek:knsh`, `rv-virt:knsh`, `rv-virt:knsh64`, `rv-virt:ksmp64`, `rv-virt:knsh_paging`, `rv-virt:knetnsh64`, `rv-virt:kfb64`, `icicle:knsh`, `canmv230:knsh`, `esp32s3-devkit:kernel_n8r2`. Flat builds with `-Wno-cpp -Werror`, size unchanged: `lm3s6965-ek:qemu-flat`, `mps2-an500:nsh`. `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]
