Empty file without "x" permission is successfully executable on Cygwin

Corinna Vinschen corinna-cygwin@cygwin.com
Tue Aug 6 09:01:00 GMT 2019


On Aug  6 10:33, Corinna Vinschen wrote:
> On Aug  6 03:19, Ken Brown wrote:
> > >>> On 8/5/2019 2:18 PM, Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin wrote:
> > >>>> Hi,
> > >>>>
> > >>>> Please consider the following shell session:
> > >>>>
> > >>>> $ cat dummy.c
> > >>>> #include <stdio.h>
> > >>>>
> > >>>> int main()
> > >>>> {
> > >>>>        return 0;
> > >>>> }
> > >>>> $ gcc -o dummy dummy.c
> > >>>> $ mv dummy.exe dummy
> > >>>> $ ./dummy
> > >>>> $ echo $?
> > >>>> 0
> > >>>> $ chmod a-x dummy
> > >>>> $ ./dummy
> > >>>> -bash: ./dummy: Permission denied
> > >>>> $ rm dummy
> > >>>> $ touch dummy
> > >>>> $ ./dummy
> > >>>> $ echo $?
> > >>>> 0
> > >>>> [...]
> > It look like what's happening is that bash calls execve(), which returns with 
> > errno ENOEXEC instead of EACCES.
> > 
> > I'll look at this more tomorrow unless someone beats me to it.
> 
> Looks like the checks for this scenario are in the wrong order.  In
> av::setup(), the first check is if the file is a valid executable and if
> so, exec returns ENOEXEC (unless called via exec[vl]p).  Only if that
> fails, av::setup checks the executability of the file(*).

Sorry, this description makes no sense.  Let me try again, here's
what av::setup does:

- Check if the file has been recognized as a she-bang script.
  - If not, checks if we have been called from exec[vl]p.
    - If not, return with ENOEXEC.
    - If yes, prepend /bin/sh to the script name.
- Check if file is executable.
  - If not, return with EACCES.
- Continue script handling.

> Ken, I'll propose a patch on cygwin-patches, please check.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20190806/4f8a741d/attachment.sig>


More information about the Cygwin mailing list