[New-bugs-announce] [issue11914] pydoc modules/help('modules') crash in dirs with unreadable subdirs

Ben Okopnik report at bugs.python.org
Sun Apr 24 05:34:53 CEST 2011


New submission from Ben Okopnik <ben at okopnik.com>:

Long-standing problem (happens in every Python version I've tested). The usual situation is when invoking Python (and then "help('modules')") or "pydoc modules" in /tmp, but also happens when located anywhere with unreadable subdirs:

ben at Jotunheim:~$ mkdir /tmp/foo; cd /tmp/foo
ben at Jotunheim:/tmp/foo$ mkdir bar; sudo chmod 000 bar
[sudo] password for ben: 
ben at Jotunheim:/tmp/foo$ pydoc modules

Please wait a moment while I gather a list of all available modules...

Traceback (most recent call last):
  File "/usr/bin/pydoc2.6", line 5, in <module>
    pydoc.cli()
  File "/usr/lib/python2.6/pydoc.py", line 2309, in cli
    help.help(arg)
  File "/usr/lib/python2.6/pydoc.py", line 1765, in help
    elif request == 'modules': self.listmodules()
  File "/usr/lib/python2.6/pydoc.py", line 1886, in listmodules
    ModuleScanner().run(callback, onerror=onerror)
  File "/usr/lib/python2.6/pydoc.py", line 1937, in run
    for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
  File "/usr/lib/python2.6/pkgutil.py", line 105, in walk_packages
    for importer, name, ispkg in iter_modules(path, prefix):
  File "/usr/lib/python2.6/pkgutil.py", line 147, in iter_modules
    for name, ispkg in iter_importer_modules(i, prefix):
  File "/usr/lib/python2.6/pkgutil.py", line 211, in iter_modules
    for fn in os.listdir(path):
OSError: [Errno 13] Permission denied: './bar'

Proposed patch:

Seems like an easy fix. In Python 3.1.2, change line 206 in /usr/lib/python3.1/pkgutil.py from

if not modname and os.path.isdir(path) and '.' not in fn:

to

if not modname and os.path.isdir(path) and '.' not in fn and os.access(path, os.R_OK):

Other versions much the same (although the specified line number will probably be different.)


Best regards,
Ben Okopnik

----------
components: Demos and Tools
messages: 134323
nosy: okopnik
priority: normal
severity: normal
status: open
title: pydoc modules/help('modules') crash in dirs with unreadable subdirs
type: crash
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4

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


More information about the New-bugs-announce mailing list