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 03:19, Ken Brown wrote:
> On 8/5/2019 4:39 PM, Ken Brown wrote:
> > On 8/5/2019 4:19 PM, Thomas Wolff wrote:
> >>
> >> Am 05.08.2019 um 22:01 schrieb Ken Brown:
> >>> 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
> >>>>
> >>>> So Cygwin lets the shell to execute a zero-sized file regardless of the "x" perm
> >>>> (non-empty files are not executable if they do not have "x", as shown above).
> >>> I can't reproduce this on my system.  Can you show the permissions and ACL of
> >>> dummy?
> >>>
> >>>> There's more.  If I put some rubbish in a file, Cygwin still tries to execute
> >>>> it even if the "x" is not there:
> >>>>
> >>>> $ rm dummy
> >>>> $ echo "1" > dummy
> >>>> $ ./dummy
> >>>> ./dummy: line 1: 1: command not found
> >>> Again I can't reproduce this.
> >> I reproduce the behaviour:
> >>   > echo echo foo > bar
> >>   > ls -l bar
> >> -rw-r--r-- 1 towo None 9  5. Aug 22:18 bar
> >>   > ./bar
> >> foo
> > 
> > You're right.  I was careless in my test.  Sorry for the noise.
> 
> 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(*).

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


Thanks,
Corinna


(*) Note that the executability test only makes sense on filesystems
    supporting execute bits.  On FAT filesystems, no such check will take
    place and Cygwin will not encounter EACCES scenarios.

-- 
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]