bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange/incorrect behavior of a fake executable file


From: Eduardo A . Bustamante López
Subject: Re: Strange/incorrect behavior of a fake executable file
Date: Fri, 16 Mar 2018 09:26:38 -0600
User-agent: Mutt/1.9.4 (2018-02-28)

On Wed, Mar 14, 2018 at 08:43:45AM -0400, Greg Wooledge wrote:
> > 1) You do not provide a hash-bang (i.e. #!/bin/bash), which means that
> > /bin/sh will be used (
> 
> No, that's incorrect.  When bash tells the operating system to run
> this program, the operating system will return ENOEXEC (Exec format
> error).  Bash (and every other shell) will catch this and spawn a
> child copy of itself to try to interpret the program as a script.

Thank you for the correction.

What misled me is that the *p variants of exec() function do fallback to
/bin/sh,

> Special semantics for execlp() and execvp() 
> [...]
> If the header of a file isn't recognized (the attempted execve(2) failed with
> the error ENOEXEC), these functions will execute the shell (/bin/sh) with the
> path of the file as its first argument. (If this attempt fails, no further
> searching is done.) 

  from: https://linux.die.net/man/3/execvp

Of course, this is incorrect for bash's case, since it uses execve(), which
does not exhibit this special behavior.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]