From 04b176caef6e3f4bc626b1174d096c70afc16dd0 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 18 May 2024 22:09:03 +0200 Subject: libc/execvpe: ENOENT on missing interpreter --- src/libc/unistd/unistd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libc/unistd/unistd.c b/src/libc/unistd/unistd.c index 9735df0..99899ce 100644 --- a/src/libc/unistd/unistd.c +++ b/src/libc/unistd/unistd.c @@ -46,8 +46,9 @@ int execvpe(const char *path, char *const argv[], char *const envp[]) { int execve(const char *path, char *const argv[], char *const envp[]) { FILE *file = fopen(path, "e"); char hdr[4] = {0}; - if (!file) - return -1; + if (!file) { + return errno = ENOENT, -1; + } fread(hdr, 1, 4, file); fseek(file, 0, SEEK_SET); @@ -55,6 +56,7 @@ int execve(const char *path, char *const argv[], char *const envp[]) { if (!memcmp("\x7f""ELF", hdr, 4)) { elf_execf(file, (void*)argv, (void*)envp); fclose(file); + errno = EINVAL; } else if (!memcmp("#!", hdr, 2)) { char buf[256]; fseek(file, 2, SEEK_SET); @@ -64,9 +66,10 @@ int execve(const char *path, char *const argv[], char *const envp[]) { if (endl) *endl = '\0'; execve(buf, (void*)argv, envp); } + } else { + errno = EINVAL; } - errno = EINVAL; return -1; } -- cgit v1.2.3