The following issues were found
Lib/test/test_flufl.py
7 issues
Line: 3
Column: 1
import __future__
import unittest
from test import support
class FLUFLTests(unittest.TestCase):
def test_barry_as_bdfl(self):
code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
Reported by Pylint.
Line: 1
Column: 1
import __future__
import unittest
from test import support
class FLUFLTests(unittest.TestCase):
def test_barry_as_bdfl(self):
code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
Reported by Pylint.
Line: 6
Column: 1
from test import support
class FLUFLTests(unittest.TestCase):
def test_barry_as_bdfl(self):
code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
compile(code.format('<>'), '<BDFL test>', 'exec',
__future__.CO_FUTURE_BARRY_AS_BDFL)
Reported by Pylint.
Line: 8
Column: 5
class FLUFLTests(unittest.TestCase):
def test_barry_as_bdfl(self):
code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
compile(code.format('<>'), '<BDFL test>', 'exec',
__future__.CO_FUTURE_BARRY_AS_BDFL)
with self.assertRaises(SyntaxError) as cm:
compile(code.format('!='), '<FLUFL test>', 'exec',
Reported by Pylint.
Line: 12
Column: 48
code = "from __future__ import barry_as_FLUFL\n2 {0} 3"
compile(code.format('<>'), '<BDFL test>', 'exec',
__future__.CO_FUTURE_BARRY_AS_BDFL)
with self.assertRaises(SyntaxError) as cm:
compile(code.format('!='), '<FLUFL test>', 'exec',
__future__.CO_FUTURE_BARRY_AS_BDFL)
self.assertRegex(str(cm.exception),
"with Barry as BDFL, use '<>' instead of '!='")
self.assertIn('2 != 3', cm.exception.text)
Reported by Pylint.
Line: 25
Column: 5
# parser reports the start of the token
self.assertEqual(cm.exception.offset, 3)
def test_guido_as_bdfl(self):
code = '2 {0} 3'
compile(code.format('!='), '<BDFL test>', 'exec')
with self.assertRaises(SyntaxError) as cm:
compile(code.format('<>'), '<FLUFL test>', 'exec')
self.assertRegex(str(cm.exception), "invalid syntax")
Reported by Pylint.
Line: 28
Column: 48
def test_guido_as_bdfl(self):
code = '2 {0} 3'
compile(code.format('!='), '<BDFL test>', 'exec')
with self.assertRaises(SyntaxError) as cm:
compile(code.format('<>'), '<FLUFL test>', 'exec')
self.assertRegex(str(cm.exception), "invalid syntax")
self.assertIn('2 <> 3', cm.exception.text)
self.assertEqual(cm.exception.filename, '<FLUFL test>')
self.assertEqual(cm.exception.lineno, 1)
Reported by Pylint.
Lib/test/test_longexp.py
7 issues
Line: 6
Column: 13
class LongExpText(unittest.TestCase):
def test_longexp(self):
REPS = 65580
l = eval("[" + "2," * REPS + "]")
self.assertEqual(len(l), REPS)
if __name__ == "__main__":
unittest.main()
Reported by Pylint.
Line: 6
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
class LongExpText(unittest.TestCase):
def test_longexp(self):
REPS = 65580
l = eval("[" + "2," * REPS + "]")
self.assertEqual(len(l), REPS)
if __name__ == "__main__":
unittest.main()
Reported by Bandit.
Line: 1
Column: 1
import unittest
class LongExpText(unittest.TestCase):
def test_longexp(self):
REPS = 65580
l = eval("[" + "2," * REPS + "]")
self.assertEqual(len(l), REPS)
if __name__ == "__main__":
Reported by Pylint.
Line: 3
Column: 1
import unittest
class LongExpText(unittest.TestCase):
def test_longexp(self):
REPS = 65580
l = eval("[" + "2," * REPS + "]")
self.assertEqual(len(l), REPS)
if __name__ == "__main__":
Reported by Pylint.
Line: 4
Column: 5
import unittest
class LongExpText(unittest.TestCase):
def test_longexp(self):
REPS = 65580
l = eval("[" + "2," * REPS + "]")
self.assertEqual(len(l), REPS)
if __name__ == "__main__":
Reported by Pylint.
Line: 5
Column: 9
class LongExpText(unittest.TestCase):
def test_longexp(self):
REPS = 65580
l = eval("[" + "2," * REPS + "]")
self.assertEqual(len(l), REPS)
if __name__ == "__main__":
unittest.main()
Reported by Pylint.
Line: 6
Column: 9
class LongExpText(unittest.TestCase):
def test_longexp(self):
REPS = 65580
l = eval("[" + "2," * REPS + "]")
self.assertEqual(len(l), REPS)
if __name__ == "__main__":
unittest.main()
Reported by Pylint.
Lib/test/test_check_c_globals.py
7 issues
Line: 6
Column: 5
test.test_tools.skip_if_missing('c-analyzer')
with test.test_tools.imports_under_tool('c-analyzer'):
from cpython.__main__ import main
class ActualChecks(unittest.TestCase):
# XXX Also run the check in "make check".
Reported by Pylint.
Line: 11
Column: 3
class ActualChecks(unittest.TestCase):
# XXX Also run the check in "make check".
#@unittest.expectedFailure
# Failing on one of the buildbots (see https://bugs.python.org/issue36876).
@unittest.skip('activate this once all the globals have been resolved')
def test_check_c_globals(self):
try:
Reported by Pylint.
Line: 19
Column: 13
try:
main('check', {})
except NotImplementedError:
raise unittest.SkipTest('not supported on this host')
if __name__ == '__main__':
# Test needs to be a package, so we can do relative imports.
unittest.main()
Reported by Pylint.
Line: 1
Column: 1
import unittest
import test.test_tools
test.test_tools.skip_if_missing('c-analyzer')
with test.test_tools.imports_under_tool('c-analyzer'):
from cpython.__main__ import main
class ActualChecks(unittest.TestCase):
Reported by Pylint.
Line: 9
Column: 1
from cpython.__main__ import main
class ActualChecks(unittest.TestCase):
# XXX Also run the check in "make check".
#@unittest.expectedFailure
# Failing on one of the buildbots (see https://bugs.python.org/issue36876).
@unittest.skip('activate this once all the globals have been resolved')
Reported by Pylint.
Line: 15
Column: 5
#@unittest.expectedFailure
# Failing on one of the buildbots (see https://bugs.python.org/issue36876).
@unittest.skip('activate this once all the globals have been resolved')
def test_check_c_globals(self):
try:
main('check', {})
except NotImplementedError:
raise unittest.SkipTest('not supported on this host')
Reported by Pylint.
Line: 15
Column: 5
#@unittest.expectedFailure
# Failing on one of the buildbots (see https://bugs.python.org/issue36876).
@unittest.skip('activate this once all the globals have been resolved')
def test_check_c_globals(self):
try:
main('check', {})
except NotImplementedError:
raise unittest.SkipTest('not supported on this host')
Reported by Pylint.
Lib/test/badsyntax_future3.py
7 issues
Line: 3
Column: 1
"""This is a test"""
from __future__ import nested_scopes
from __future__ import rested_snopes
def f(x):
def g(y):
return x + y
return g
Reported by Pylint.
Line: 5
Column: 1
from __future__ import nested_scopes
from __future__ import rested_snopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 5
Column: 1
from __future__ import nested_scopes
from __future__ import rested_snopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 5
Column: 1
from __future__ import nested_scopes
from __future__ import rested_snopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 6
Column: 5
from __future__ import rested_snopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 6
Column: 5
from __future__ import rested_snopes
def f(x):
def g(y):
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Line: 10
Column: 1
return x + y
return g
result = f(2)(4)
Reported by Pylint.
Lib/test/dis_module.py
7 issues
Line: 1
Column: 1
# A simple module for testing the dis module.
def f(): pass
def g(): pass
Reported by Pylint.
Line: 4
Column: 1
# A simple module for testing the dis module.
def f(): pass
def g(): pass
Reported by Pylint.
Line: 4
Column: 1
# A simple module for testing the dis module.
def f(): pass
def g(): pass
Reported by Pylint.
Line: 4
Column: 10
# A simple module for testing the dis module.
def f(): pass
def g(): pass
Reported by Pylint.
Line: 5
Column: 10
# A simple module for testing the dis module.
def f(): pass
def g(): pass
Reported by Pylint.
Line: 5
Column: 1
# A simple module for testing the dis module.
def f(): pass
def g(): pass
Reported by Pylint.
Line: 5
Column: 1
# A simple module for testing the dis module.
def f(): pass
def g(): pass
Reported by Pylint.
Lib/test/leakers/test_selftype.py
7 issues
Line: 1
Column: 1
# Reference cycles involving only the ob_type field are rather uncommon
# but possible. Inspired by SF bug 1469629.
import gc
def leak():
class T(type):
pass
class U(type, metaclass=T):
Reported by Pylint.
Line: 6
Column: 1
import gc
def leak():
class T(type):
pass
class U(type, metaclass=T):
pass
U.__class__ = U
Reported by Pylint.
Line: 7
Column: 5
import gc
def leak():
class T(type):
pass
class U(type, metaclass=T):
pass
U.__class__ = U
del U
Reported by Pylint.
Line: 7
Column: 5
import gc
def leak():
class T(type):
pass
class U(type, metaclass=T):
pass
U.__class__ = U
del U
Reported by Pylint.
Line: 9
Column: 5
def leak():
class T(type):
pass
class U(type, metaclass=T):
pass
U.__class__ = U
del U
gc.collect(); gc.collect(); gc.collect()
Reported by Pylint.
Line: 9
Column: 5
def leak():
class T(type):
pass
class U(type, metaclass=T):
pass
U.__class__ = U
del U
gc.collect(); gc.collect(); gc.collect()
Reported by Pylint.
Line: 13
Column: 19
pass
U.__class__ = U
del U
gc.collect(); gc.collect(); gc.collect()
Reported by Pylint.
Modules/_ctypes/_ctypes_test.c
7 issues
Line: 284
Column: 14
CWE codes:
134
Suggestion:
Use a constant for the format specification
int result;
va_list argptr;
va_start(argptr, fmt);
result = vprintf(fmt, argptr);
va_end(argptr);
return result;
}
EXPORT(char *)my_strtok(char *token, const char *delim)
Reported by FlawFinder.
Line: 372
Column: 5
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
char *dst = (char *)malloc(strlen(src)+1);
if (!dst)
return NULL;
strcpy(dst, src);
return dst;
}
EXPORT(void)my_free(void *ptr)
{
Reported by FlawFinder.
Line: 78
Column: 14
CWE codes:
119
120
Suggestion:
Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length
*/
typedef struct {
unsigned char data[16];
} Test2;
EXPORT(int)
_testfunc_array_in_struct1(Test2 in)
{
Reported by FlawFinder.
Line: 388
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
if (ptr == NULL)
return NULL;
memcpy(ptr, src, (len+1) * sizeof(wchar_t));
return ptr;
}
EXPORT(size_t) my_wcslen(wchar_t *src)
{
Reported by FlawFinder.
Line: 369
Column: 32
CWE codes:
126
EXPORT(char *) my_strdup(char *src)
{
char *dst = (char *)malloc(strlen(src)+1);
if (!dst)
return NULL;
strcpy(dst, src);
return dst;
}
Reported by FlawFinder.
Line: 384
Column: 18
CWE codes:
126
#ifdef HAVE_WCHAR_H
EXPORT(wchar_t *) my_wcsdup(wchar_t *src)
{
size_t len = wcslen(src);
wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
if (ptr == NULL)
return NULL;
memcpy(ptr, src, (len+1) * sizeof(wchar_t));
return ptr;
Reported by FlawFinder.
Line: 394
Column: 12
CWE codes:
126
EXPORT(size_t) my_wcslen(wchar_t *src)
{
return wcslen(src);
}
#endif
#ifndef MS_WIN32
# ifndef __stdcall
Reported by FlawFinder.
Tools/c-analyzer/cpython/_parser.py
7 issues
Line: 11
Column: 1
parse_file as _parse_file,
parse_files as _parse_files,
)
from . import REPO_ROOT
GLOB_ALL = '**/*'
Reported by Pylint.
Line: 29
Column: 1
return list(lines)
'''
@begin=sh@
./python ../c-parser/cpython.py
--exclude '+../c-parser/EXCLUDED'
--macros '+../c-parser/MACROS'
--incldirs '+../c-parser/INCL_DIRS'
Reported by Pylint.
Line: 82
Column: 3
# @end=conf@
''')
# XXX Fix the parser.
EXCLUDED += clean_lines('''
# The tool should be able to parse these...
Modules/hashlib.h
Objects/stringlib/codecs.h
Reported by Pylint.
Line: 1
Column: 1
import os.path
import re
from c_parser.preprocessor import (
get_preprocessor as _get_preprocessor,
)
from c_parser import (
parse_file as _parse_file,
parse_files as _parse_files,
Reported by Pylint.
Line: 269
Column: 1
]
def get_preprocessor(*,
file_macros=None,
file_incldirs=None,
file_same=None,
**kwargs
):
Reported by Pylint.
Line: 289
Column: 1
)
def parse_file(filename, *,
match_kind=None,
ignore_exc=None,
log_err=None,
):
get_file_preprocessor = get_preprocessor(
Reported by Pylint.
Line: 305
Column: 1
)
def parse_files(filenames=None, *,
match_kind=None,
ignore_exc=None,
log_err=None,
get_file_preprocessor=None,
**file_kwargs
Reported by Pylint.
Lib/test/test_wait3.py
7 issues
Line: 33
Column: 26
time.sleep(0.1)
self.assertEqual(spid, cpid)
self.assertEqual(os.waitstatus_to_exitcode(status), exitcode)
self.assertTrue(rusage)
def test_wait3_rusage_initialized(self):
# Ensure a successful wait3() call where no child was ready to report
# its exit status does not return uninitialized memory in the rusage
Reported by Pylint.
Line: 5
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
"""
import os
import subprocess
import sys
import time
import unittest
from test.fork_wait import ForkWait
from test import support
Reported by Bandit.
Line: 18
Column: 1
if not hasattr(os, 'wait3'):
raise unittest.SkipTest("os.wait3 not defined")
class Wait3Test(ForkWait):
def wait_impl(self, cpid, *, exitcode):
# This many iterations can be required, since some previously run
# tests (e.g. test_ctypes) could have spawned a lot of children
# very quickly.
deadline = time.monotonic() + support.SHORT_TIMEOUT
Reported by Pylint.
Line: 36
Column: 5
self.assertEqual(os.waitstatus_to_exitcode(status), exitcode)
self.assertTrue(rusage)
def test_wait3_rusage_initialized(self):
# Ensure a successful wait3() call where no child was ready to report
# its exit status does not return uninitialized memory in the rusage
# structure. See bpo-36279.
args = [sys.executable, '-c', 'import sys; sys.stdin.read()']
proc = subprocess.Popen(args, stdin=subprocess.PIPE)
Reported by Pylint.
Line: 41
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html
# its exit status does not return uninitialized memory in the rusage
# structure. See bpo-36279.
args = [sys.executable, '-c', 'import sys; sys.stdin.read()']
proc = subprocess.Popen(args, stdin=subprocess.PIPE)
try:
pid, status, rusage = os.wait3(os.WNOHANG)
self.assertEqual(0, pid)
self.assertEqual(0, status)
self.assertEqual(0, sum(rusage))
Reported by Bandit.
Line: 52
Column: 1
proc.wait()
def tearDownModule():
support.reap_children()
if __name__ == "__main__":
unittest.main()
Reported by Pylint.
Line: 52
Column: 1
proc.wait()
def tearDownModule():
support.reap_children()
if __name__ == "__main__":
unittest.main()
Reported by Pylint.
Objects/typeslots.py
7 issues
Line: 1
Column: 1
#!/usr/bin/python
# Usage: typeslots.py < Include/typeslots.h typeslots.inc
import sys, re
def generate_typeslots(out=sys.stdout):
out.write("/* Generated by typeslots.py */\n")
res = {}
Reported by Pylint.
Line: 4
Column: 1
#!/usr/bin/python
# Usage: typeslots.py < Include/typeslots.h typeslots.inc
import sys, re
def generate_typeslots(out=sys.stdout):
out.write("/* Generated by typeslots.py */\n")
res = {}
Reported by Pylint.
Line: 7
Column: 1
import sys, re
def generate_typeslots(out=sys.stdout):
out.write("/* Generated by typeslots.py */\n")
res = {}
for line in sys.stdin:
m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
if not m:
Reported by Pylint.
Line: 11
Column: 9
out.write("/* Generated by typeslots.py */\n")
res = {}
for line in sys.stdin:
m = re.match("#define Py_([a-z_]+) ([0-9]+)", line)
if not m:
continue
member = m.group(1)
if member.startswith("tp_"):
Reported by Pylint.
Line: 35
Column: 5
' offsetof(PyTypeObject, tp_as_buffer)}')
res[int(m.group(2))] = member
M = max(res.keys())+1
for i in range(1,M):
if i in res:
out.write("%s,\n" % res[i])
else:
out.write("{0, 0},\n")
Reported by Pylint.
Line: 43
Column: 1
out.write("{0, 0},\n")
def main():
if len(sys.argv) == 2:
with open(sys.argv[1], "w") as f:
generate_typeslots(f)
else:
generate_typeslots()
Reported by Pylint.
Line: 45
Column: 40
def main():
if len(sys.argv) == 2:
with open(sys.argv[1], "w") as f:
generate_typeslots(f)
else:
generate_typeslots()
if __name__ == "__main__":
Reported by Pylint.