[New-bugs-announce] [issue9311] os.access can return bogus values when run as superuser

Garrett Cooper 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 [1], 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:

import os
import stat

s = os.stat(afile)

executable = (s.st_mode & stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) == 0

[1] http://code.google.com/p/python-nose/issues/detail?id=351
[2] http://www.opengroup.org/onlinepubs/000095399/functions/access.html

----------
components: Library (Lib)
messages: 110850
nosy: yaneurabeya
priority: normal
severity: normal
status: open
title: os.access can return bogus values when run as superuser
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9311>
_______________________________________


More information about the New-bugs-announce mailing list