Fix infinite loop issue
Running bandit using relative paths inside a subdirectory when the current directory contains __init__.py causes bandit to be stuck in an infinite loop. Co-Authored-By: Calvin Li Closes-Bug: #1743042 Change-Id: I247108c1365847134ee561073ea0eb43c57b54cc
This commit is contained in:
parent
d22d76c9da
commit
90f031c973
|
@ -151,7 +151,7 @@ def get_module_qualname_from_path(path):
|
||||||
' Missing path or file name' % (path))
|
' Missing path or file name' % (path))
|
||||||
|
|
||||||
qname = [os.path.splitext(tail)[0]]
|
qname = [os.path.splitext(tail)[0]]
|
||||||
while head not in ['/', '.']:
|
while head not in ['/', '.', '']:
|
||||||
if os.path.isfile(os.path.join(head, '__init__.py')):
|
if os.path.isfile(os.path.join(head, '__init__.py')):
|
||||||
(head, tail) = os.path.split(head)
|
(head, tail) = os.path.split(head)
|
||||||
qname.insert(0, tail)
|
qname.insert(0, tail)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# A sample test file in a subdirectory and its parents both containing
|
||||||
|
# an __init__.py file outlined in bug/1743042.
|
||||||
|
print('hopefully no vulnerabilities here')
|
|
@ -121,6 +121,8 @@ source-dir = doc/source
|
||||||
|
|
||||||
[pbr]
|
[pbr]
|
||||||
autodoc_tree_index_modules = True
|
autodoc_tree_index_modules = True
|
||||||
|
autodoc_tree_excludes =
|
||||||
|
examples*
|
||||||
|
|
||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
universal = 1
|
universal = 1
|
||||||
|
|
|
@ -285,6 +285,14 @@ class FunctionalTests(testtools.TestCase):
|
||||||
}
|
}
|
||||||
self.check_example('okay.py', expect)
|
self.check_example('okay.py', expect)
|
||||||
|
|
||||||
|
def test_subdirectory_okay(self):
|
||||||
|
'''Test a vulnerability-free file under a subdirectory.'''
|
||||||
|
expect = {
|
||||||
|
'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 0},
|
||||||
|
'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 0}
|
||||||
|
}
|
||||||
|
self.check_example('init-py-test/subdirectory-okay.py', expect)
|
||||||
|
|
||||||
def test_os_chmod(self):
|
def test_os_chmod(self):
|
||||||
'''Test setting file permissions.'''
|
'''Test setting file permissions.'''
|
||||||
filename = 'os-chmod-{}.py'
|
filename = 'os-chmod-{}.py'
|
||||||
|
|
Loading…
Reference in New Issue