[issue9311] os.access can return bogus values when run as superuser
report at bugs.python.org
Tue Jul 20 04:02:37 CEST 2010
New submission from Garrett Cooper <yanegomi at gmail.com>:
As seen in the nose bug , I stumbled upon an OS quirk with FreeBSD, where apparently (as superuser) due to the wording of the POSIX spec for access(2), it's considered free game to return 0 for the system call (True) for os.[RWX]_OK.
Only python was affected by this on the system I was using (both perl and sh did the right thing in detecting the executable bit(s) on the file).
An example should be provided to do the right thing with the stat module, and developers should be warned against using os.access because (as the patch and test log demonstrate), stat(2) does the right thing when access(2) does not as superuser...
Here's an example of the code I used to detect the executable bit:
s = os.stat(afile)
executable = (s.st_mode & stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) == 0
components: Library (Lib)
title: os.access can return bogus values when run as superuser
versions: Python 2.6
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list