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 d51cfb39746a1106a0e9b34f9b4779fb07f46511 Author: Marco Casaroli <[email protected]> AuthorDate: Sun Oct 11 11:43:26 2026 +0200 libs/libc/elf: Return ENOEXEC for a file shorter than an ELF header. exec() of a file that is shorter than an ELF header, for example a short shell script without "#!", failed with ENODATA: the read of the header reached the end of the file. POSIX says that exec() fails with ENOEXEC when the file has an unrecognized format, and shells run such a file themselves only on ENOEXEC: a shell printed "No data available" instead of running the script. Return ENOEXEC when the file ends before the ELF header, as for any other file that is not an ELF file. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- libs/libc/elf/elf_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/libc/elf/elf_init.c b/libs/libc/elf/elf_init.c index 8493c367dd1..cbef6e1ba5a 100644 --- a/libs/libc/elf/elf_init.c +++ b/libs/libc/elf/elf_init.c @@ -134,8 +134,10 @@ int libelf_initialize(FAR const char *filename, sizeof(Elf_Ehdr), 0); if (ret < 0) { + /* A file that is shorter than an ELF header is not an ELF file */ + berr("ERROR: Failed to read ELF header: %d\n", ret); - return ret; + return ret == -ENODATA ? -ENOEXEC : ret; } libelf_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr,
