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: Vladimir Likic
Subject: Re: Strange/incorrect behavior of a fake executable file
Date: Thu, 15 Mar 2018 08:36:07 +1100

Hi Eduardo (and all),

I was actually not doing anything useful, just playing with bash. I've got
so used to putting '#! /bin/bash' at the top of the file, that I've
completely forgotten that bash will attempt to execute commands even
without hash-bang. Compounded to that, intuitively, I didn't expect that
something as simple as:

$ echo ./junk > junk
$ chmod +x junk
$ ./junk

will be allowed (with poorly reproducible, bad consequences).

Of course my bad, and that double. Thank you all for the prompt responses,
good lesson!

Cheers,
Vlad


On Thu, Mar 15, 2018 at 7:02 AM, Eduardo Bustamante <dualbus@gmail.com>
wrote:

> (I've added bug-bash again)
>
> On Tue, Mar 13, 2018 at 11:32 PM, Vladimir Likic <v.likic@gmail.com>
> wrote:
> > Thanks for the quick response!
>
> > Your are correct, "." was in PATH (my bad), an it's calling itself
> > recursively. That went into a spiral and crashed the computer
> (literally).
>
> > Why is bash actually executing the file without '!#' ?
>
> [...]
>
> On Tue, Mar 13, 2018 at 11:34 PM, Vladimir Likic <v.likic@gmail.com>
> wrote:
> > Sorry, meant why is bash executing the file without hash-bang '#!' ?
>
> You can see the answer here:
> http://git.savannah.gnu.org/cgit/bash.git/tree/execute_cmd.c?h=devel&id=
> bf5b8103d466fdbc3bfcdaa5e21a0d0c0dce7cba#n5608
>
> Oversimplified explanation:
>
> Bash performs the execve() system call on the executable file
> (`junk'). If the system returns ENOEXEC (i.e. not an executable), bash
> will then try to execute the file itself
>


reply via email to

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