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

2011-04-27 Thread Ben Okopnik

Ben Okopnik b...@okopnik.com added the comment:

Here's a test that should exercise every version of pydoc installed on the 
system:

mkdir -p /tmp/foo/bar; cd /tmp/foo; chmod 0 bar
for n in `whereis -b pydoc`; do echo  $n ; $n modules; done

Tested under Ubuntu with bash and sh; should work fine with any Bourne-derived 
shell that supports 'whereis'. Please see attached file.

--
Added file: http://bugs.python.org/file21803/pydoc_crash_test

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11914
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2011-04-27 Thread Ben Okopnik

Ben Okopnik b...@okopnik.com added the comment:

Trivial fix: please see attached. As to test_pydoc.py, I don't know the system 
well enough to fiddle with it, but something like this should work (untested):

def test_unreadable_dir(self):
''' pydoc should handle unreadable subdirs gracefully '''

@contextmanager
def mk_unreadable_dir():
top_level_dir = tempfile.mkdtemp()
bad_dir = tempfile.mkdtemp(dir=top_level_dir)
os.chmod(bad_dir, 0)
os.chdir(top_level_dir)
yield
os.removedirs(top_level_dir)

with mk_unreadable_dir():
doc = pydoc.render_doc('modules')
self.assertTrue(modules in doc)

--
Added file: http://bugs.python.org/file21807/pydoc_crash_test

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11914
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2011-04-27 Thread Ben Okopnik

Ben Okopnik b...@okopnik.com added the comment:

Whoops... with all of that, I just realized that this bug should be filed 
against pkgutil, not pydoc (pydoc, of course, calls pkgutil to do the path 
resolution, which is where this crash occurs.) My bad.

 import pkgutil
 inst = pkgutil.ImpImporter(path='/tmp')
 list(inst.iter_modules())
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python3.1/pkgutil.py, line 209, in iter_modules
for fn in os.listdir(path):
OSError: [Errno 13] Permission denied: '/tmp/orbit-gdm'

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11914
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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

2011-04-23 Thread Ben Okopnik

New submission from Ben Okopnik b...@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@Jotunheim:~$ mkdir /tmp/foo; cd /tmp/foo
ben@Jotunheim:/tmp/foo$ mkdir bar; sudo chmod 000 bar
[sudo] password for ben: 
ben@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 rep...@bugs.python.org
http://bugs.python.org/issue11914
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com