mailing list of musl libc
 help / color / mirror / code / Atom feed
* No fallback to /bin/sh in execvp
@ 2018-03-09 12:23 Siebenborn, Axel
  2018-03-09 17:01 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Siebenborn, Axel @ 2018-03-09 12:23 UTC (permalink / raw)
  To: musl

Hi,

I encountered a problem with execvp with musl.
Trying to execute shell scripts without #! fails with ENOEXEC.
However, according to the standard, execvp should fallback to execute the file using /bin/sh.

A simple test:

Create a  script file 'prog'  without '!#' with the following content and make it executable:

/bin/echo "$@" 

Compile and run the following c-program:

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

int main (){
  int ret;
  char *cmd[] = { "./prog","Hello", "World", (char *)0 };
  ret = execvp ("./prog", cmd);
  int errorNumber = errno;
  printf("Error code: %d. Error message: %s\n", errorNumber, strerror(errorNumber));
}

With musl the execution results in the following error:

Error code: 8. Error message: Exec format error

With glibs 'Hello world' is printed.

Is this a bug, that will be fixed someday or intended behavior for security reasons.

I think it's a quiet a strange way to execute shell commands. However, some ancient code might rely on this 
and compatibility wins over sanity,

Kind regards,
Axel



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-11 13:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-09 12:23 No fallback to /bin/sh in execvp Siebenborn, Axel
2018-03-09 17:01 ` Rich Felker
2018-03-11 13:47   ` [PATCH] Continue trying execution with "/bin/sh" for execlp and execvp Quentin Rameau

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).