Hi Takashi, On Dec 8 16:43, Takashi Yano wrote: > Previous fhandler_base::fstat_helper() does not assume get_stat_handle() > returns NULL. Due to this, access() for network share which has not been > authenticated returns 0 (success). This patch add error handling to > fhandler_base::fstat_helper() for get_stat_handle() failure. > > Fixed: 5a0d1edba4b3 [...] ^^^^^ Fixes
> Reviewed-by: > Signed-off-by: Takashi Yano <takashi.y...@nifty.ne.jp> > --- > winsup/cygwin/fhandler/disk_file.cc | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/winsup/cygwin/fhandler/disk_file.cc > b/winsup/cygwin/fhandler/disk_file.cc > index 2008fb61b..7c3c805fd 100644 > --- a/winsup/cygwin/fhandler/disk_file.cc > +++ b/winsup/cygwin/fhandler/disk_file.cc > @@ -400,6 +400,11 @@ fhandler_base::fstat_helper (struct stat *buf) > IO_STATUS_BLOCK st; > FILE_COMPRESSION_INFORMATION fci; > HANDLE h = get_stat_handle (); > + if (h == NULL) > + { > + __seterrno (); > + return -1; > + } > PFILE_ALL_INFORMATION pfai = pc.fai (); > ULONG attributes = pc.file_attributes (); This introduces a regression from the user perspective. The underlying fstat functions were meant to return *something*, no matter how few information we got, as long as the file exists. The reason is, for example, that Windows disallows to fetch stat(2) information on files you don't have permissions on. For instance, pagefile.sys. On POSIX, you don't expect that stat(2) fails for these files, even if you can't access them in any other way. So prior to your patch, ls doesn't fail on pagefile.sys: $ ls -l /cygdrive/c/pagefile.sys -rw-r----- 1 Unknown+User Unknown+Group 2550136832 Dec 1 11:45 /cygdrive/c/pagefile.sys The file exists, the stat(2) info is partially available. After your patch: $ ls -l /cygdrive/c/pagefile.sys ls: cannot access '/cygdrive/c/pagefile.sys': Device or resource busy Along these lines, if a share exists and is visible, stat(2) info should be available just the same as for pagefile.sys, even if you can't access the share otherwise. Corinna