From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12594 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: No fallback to /bin/sh in execvp Date: Fri, 9 Mar 2018 12:01:40 -0500 Message-ID: <20180309170140.GQ1436@brightrain.aerifal.cx> References: <3a04ed7d2f8748a79941a3676658fc25@sap.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1520614795 9881 195.159.176.226 (9 Mar 2018 16:59:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 9 Mar 2018 16:59:55 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12608-gllmg-musl=m.gmane.org@lists.openwall.com Fri Mar 09 17:59:51 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1euLMz-0002RG-Sv for gllmg-musl@m.gmane.org; Fri, 09 Mar 2018 17:59:49 +0100 Original-Received: (qmail 18229 invoked by uid 550); 9 Mar 2018 17:01:53 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 18206 invoked from network); 9 Mar 2018 17:01:52 -0000 Content-Disposition: inline In-Reply-To: <3a04ed7d2f8748a79941a3676658fc25@sap.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12594 Archived-At: 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 > #include > #include > #include > > 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