mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: No fallback to /bin/sh in execvp
Date: Fri, 9 Mar 2018 12:01:40 -0500	[thread overview]
Message-ID: <20180309170140.GQ1436@brightrain.aerifal.cx> (raw)
In-Reply-To: <3a04ed7d2f8748a79941a3676658fc25@sap.com>

On Fri, Mar 09, 2018 at 12:23:06PM +0000, Siebenborn, Axel wrote:
> 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,

It's a bug, but one that was considered low priority since real-world
usage is for scripts to start with #!, in which case the kernel
handles invocation. Actually doing what the standard requires here
seems hard since we'd need to allocate storage for the new argv...

Rich


  reply	other threads:[~2018-03-09 17:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 12:23 Siebenborn, Axel
2018-03-09 17:01 ` Rich Felker [this message]
2018-03-11 13:47   ` [PATCH] Continue trying execution with "/bin/sh" for execlp and execvp Quentin Rameau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180309170140.GQ1436@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).