This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]