The following issues were found
Tools/scripts/smelly.py
13 issues
Line: 46
Column: 12
args.append('--dynamic')
args.append(library)
print("+ %s" % ' '.join(args))
proc = subprocess.run(args, stdout=subprocess.PIPE, universal_newlines=True)
if proc.returncode:
sys.stdout.write(proc.stdout)
sys.exit(proc.returncode)
stdout = proc.stdout.rstrip()
Reported by Pylint.
Line: 1
Column: 1
#!/usr/bin/env python
# Script checking that all symbols exported by libpython start with Py or _Py
import os.path
import subprocess
import sys
import sysconfig
Reported by Pylint.
Line: 5
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
# Script checking that all symbols exported by libpython start with Py or _Py
import os.path
import subprocess
import sys
import sysconfig
ALLOWED_PREFIXES = ('Py', '_Py')
Reported by Bandit.
Line: 19
Column: 1
IGNORED_SYMBOLS = {'_init', '_fini'}
def is_local_symbol_type(symtype):
# Ignore local symbols.
# If lowercase, the symbol is usually local; if uppercase, the symbol
# is global (external). There are however a few lowercase symbols that
# are shown for special global symbols ("u", "v" and "w").
Reported by Pylint.
Line: 37
Column: 1
return False
def get_exported_symbols(library, dynamic=False):
print(f"Check that {library} only exports symbols starting with Py or _Py")
# Only look at dynamic symbols
args = ['nm', '--no-sort']
if dynamic:
Reported by Pylint.
Line: 46
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html
args.append('--dynamic')
args.append(library)
print("+ %s" % ' '.join(args))
proc = subprocess.run(args, stdout=subprocess.PIPE, universal_newlines=True)
if proc.returncode:
sys.stdout.write(proc.stdout)
sys.exit(proc.returncode)
stdout = proc.stdout.rstrip()
Reported by Bandit.
Line: 57
Column: 1
return stdout
def get_smelly_symbols(stdout):
smelly_symbols = []
python_symbols = []
local_symbols = []
for line in stdout.splitlines():
Reported by Pylint.
Line: 91
Column: 1
return smelly_symbols, python_symbols
def check_library(library, dynamic=False):
nm_output = get_exported_symbols(library, dynamic)
smelly_symbols, python_symbols = get_smelly_symbols(nm_output)
if not smelly_symbols:
print(f"OK: no smelly symbol found ({len(python_symbols)} Python symbols)")
Reported by Pylint.
Line: 109
Column: 1
return len(smelly_symbols)
def check_extensions():
print(__file__)
srcdir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
filename = os.path.join(srcdir, "pybuilddir.txt")
try:
with open(filename, encoding="utf-8") as fp:
Reported by Pylint.
Line: 114
Column: 50
srcdir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
filename = os.path.join(srcdir, "pybuilddir.txt")
try:
with open(filename, encoding="utf-8") as fp:
pybuilddir = fp.readline()
except FileNotFoundError:
print(f"Cannot check extensions because {filename} does not exist")
return True
Reported by Pylint.
Tools/scripts/db2pickle.py
13 issues
Line: 74
Column: 14
return 1
dbopen = None
for opt, arg in opts:
if opt in ("-h", "--hash"):
try:
dbopen = bsddb.hashopen
except AttributeError:
sys.stderr.write("bsddb module unavailable.\n")
Reported by Pylint.
Line: 41
Column: 5
anydbm = None
import sys
try:
import pickle as pickle
except ImportError:
import pickle
prog = sys.argv[0]
Reported by Pylint.
Line: 41
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b403-import-pickle
anydbm = None
import sys
try:
import pickle as pickle
except ImportError:
import pickle
prog = sys.argv[0]
Reported by Bandit.
Line: 43
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b403-import-pickle
try:
import pickle as pickle
except ImportError:
import pickle
prog = sys.argv[0]
def usage():
sys.stderr.write(__doc__ % globals())
Reported by Bandit.
Line: 47
Column: 1
prog = sys.argv[0]
def usage():
sys.stderr.write(__doc__ % globals())
def main(args):
try:
opts, args = getopt.getopt(args, "hbrdag",
Reported by Pylint.
Line: 50
Column: 1
def usage():
sys.stderr.write(__doc__ % globals())
def main(args):
try:
opts, args = getopt.getopt(args, "hbrdag",
["hash", "btree", "recno", "dbm",
"gdbm", "anydbm"])
except getopt.error:
Reported by Pylint.
Line: 50
Column: 1
def usage():
sys.stderr.write(__doc__ % globals())
def main(args):
try:
opts, args = getopt.getopt(args, "hbrdag",
["hash", "btree", "recno", "dbm",
"gdbm", "anydbm"])
except getopt.error:
Reported by Pylint.
Line: 50
Column: 1
def usage():
sys.stderr.write(__doc__ % globals())
def main(args):
try:
opts, args = getopt.getopt(args, "hbrdag",
["hash", "btree", "recno", "dbm",
"gdbm", "anydbm"])
except getopt.error:
Reported by Pylint.
Line: 50
Column: 1
def usage():
sys.stderr.write(__doc__ % globals())
def main(args):
try:
opts, args = getopt.getopt(args, "hbrdag",
["hash", "btree", "recno", "dbm",
"gdbm", "anydbm"])
except getopt.error:
Reported by Pylint.
Line: 59
Column: 5
usage()
return 1
if len(args) == 0 or len(args) > 2:
usage()
return 1
elif len(args) == 1:
dbfile = args[0]
pfile = sys.stdout
Reported by Pylint.
Tools/unicode/comparecodecs.py
12 issues
Line: 21
Column: 9
u = chr(i)
try:
c1 = u.encode(encoding1)
except UnicodeError as reason:
c1 = '<undefined>'
try:
c2 = u.encode(encoding2)
except UnicodeError as reason:
c2 = '<undefined>'
Reported by Pylint.
Line: 12
Column: 1
"""
import sys
def compare_codecs(encoding1, encoding2):
print('Comparing encoding/decoding of %r and %r' % (encoding1, encoding2))
mismatch = 0
# Check encoding
for i in range(sys.maxunicode+1):
Reported by Pylint.
Line: 18
Column: 9
mismatch = 0
# Check encoding
for i in range(sys.maxunicode+1):
u = chr(i)
try:
c1 = u.encode(encoding1)
except UnicodeError as reason:
c1 = '<undefined>'
try:
Reported by Pylint.
Line: 20
Column: 13
for i in range(sys.maxunicode+1):
u = chr(i)
try:
c1 = u.encode(encoding1)
except UnicodeError as reason:
c1 = '<undefined>'
try:
c2 = u.encode(encoding2)
except UnicodeError as reason:
Reported by Pylint.
Line: 22
Column: 13
try:
c1 = u.encode(encoding1)
except UnicodeError as reason:
c1 = '<undefined>'
try:
c2 = u.encode(encoding2)
except UnicodeError as reason:
c2 = '<undefined>'
if c1 != c2:
Reported by Pylint.
Line: 24
Column: 13
except UnicodeError as reason:
c1 = '<undefined>'
try:
c2 = u.encode(encoding2)
except UnicodeError as reason:
c2 = '<undefined>'
if c1 != c2:
print(' * encoding mismatch for 0x%04X: %-14r != %r' % \
(i, c1, c2))
Reported by Pylint.
Line: 26
Column: 13
try:
c2 = u.encode(encoding2)
except UnicodeError as reason:
c2 = '<undefined>'
if c1 != c2:
print(' * encoding mismatch for 0x%04X: %-14r != %r' % \
(i, c1, c2))
mismatch += 1
# Check decoding
Reported by Pylint.
Line: 33
Column: 9
mismatch += 1
# Check decoding
for i in range(256):
c = bytes([i])
try:
u1 = c.decode(encoding1)
except UnicodeError:
u1 = '<undefined>'
try:
Reported by Pylint.
Line: 35
Column: 13
for i in range(256):
c = bytes([i])
try:
u1 = c.decode(encoding1)
except UnicodeError:
u1 = '<undefined>'
try:
u2 = c.decode(encoding2)
except UnicodeError:
Reported by Pylint.
Line: 37
Column: 13
try:
u1 = c.decode(encoding1)
except UnicodeError:
u1 = '<undefined>'
try:
u2 = c.decode(encoding2)
except UnicodeError:
u2 = '<undefined>'
if u1 != u2:
Reported by Pylint.
Tools/scripts/fixnotice.py
12 issues
Line: 60
Column: 5
def main():
global DRYRUN, OLD_NOTICE, NEW_NOTICE, VERBOSE
try:
opts, args = getopt.getopt(sys.argv[1:], 'hv',
['help', 'oldnotice=', 'newnotice=',
'dry-run', 'verbose'])
except getopt.error as msg:
Reported by Pylint.
Line: 43
Column: 1
redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
******************************************************************/
"""
import os
import sys
import getopt
NEW_NOTICE = ""
DRYRUN = 0
Reported by Pylint.
Line: 44
Column: 1
******************************************************************/
"""
import os
import sys
import getopt
NEW_NOTICE = ""
DRYRUN = 0
VERBOSE = 0
Reported by Pylint.
Line: 45
Column: 1
"""
import os
import sys
import getopt
NEW_NOTICE = ""
DRYRUN = 0
VERBOSE = 0
Reported by Pylint.
Line: 52
Column: 1
VERBOSE = 0
def usage(code, msg=''):
print(__doc__ % globals())
if msg:
print(msg)
sys.exit(code)
Reported by Pylint.
Line: 59
Column: 1
sys.exit(code)
def main():
global DRYRUN, OLD_NOTICE, NEW_NOTICE, VERBOSE
try:
opts, args = getopt.getopt(sys.argv[1:], 'hv',
['help', 'oldnotice=', 'newnotice=',
'dry-run', 'verbose'])
Reported by Pylint.
Line: 76
Column: 31
elif opt == '--dry-run':
DRYRUN = 1
elif opt == '--oldnotice':
with open(arg) as fp:
OLD_NOTICE = fp.read()
elif opt == '--newnotice':
with open(arg) as fp:
NEW_NOTICE = fp.read()
Reported by Pylint.
Line: 79
Column: 31
with open(arg) as fp:
OLD_NOTICE = fp.read()
elif opt == '--newnotice':
with open(arg) as fp:
NEW_NOTICE = fp.read()
for arg in args:
process(arg)
Reported by Pylint.
Line: 86
Column: 1
process(arg)
def process(file):
with open(file) as f:
data = f.read()
i = data.find(OLD_NOTICE)
if i < 0:
if VERBOSE:
Reported by Pylint.
Line: 87
Column: 24
def process(file):
with open(file) as f:
data = f.read()
i = data.find(OLD_NOTICE)
if i < 0:
if VERBOSE:
print('no change:', file)
Reported by Pylint.
Tools/peg_generator/scripts/grammar_grapher.py
12 issues
Line: 29
Column: 1
sys.path.insert(0, ".")
from pegen.build import build_parser
from pegen.grammar import (
Alt,
Cut,
Grammar,
Group,
Leaf,
Reported by Pylint.
Line: 94
Column: 18
args = argparser.parse_args()
try:
grammar, parser, tokenizer = build_parser(args.grammar_file)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
references = {}
Reported by Pylint.
Line: 94
Column: 26
args = argparser.parse_args()
try:
grammar, parser, tokenizer = build_parser(args.grammar_file)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
references = {}
Reported by Pylint.
Line: 95
Column: 5
try:
grammar, parser, tokenizer = build_parser(args.grammar_file)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
references = {}
for name, rule in grammar.rules.items():
Reported by Pylint.
Line: 95
Column: 12
try:
grammar, parser, tokenizer = build_parser(args.grammar_file)
except Exception as err:
print("ERROR: Failed to parse grammar file", file=sys.stderr)
sys.exit(1)
references = {}
for name, rule in grammar.rules.items():
Reported by Pylint.
Line: 28
Column: 1
sys.path.insert(0, ".")
from pegen.build import build_parser
from pegen.grammar import (
Alt,
Cut,
Grammar,
Group,
Reported by Pylint.
Line: 29
Column: 1
sys.path.insert(0, ".")
from pegen.build import build_parser
from pegen.grammar import (
Alt,
Cut,
Grammar,
Group,
Leaf,
Reported by Pylint.
Line: 58
Column: 1
argparser.add_argument("grammar_file", help="The grammar file to graph")
def references_for_item(item: Any) -> List[Any]:
if isinstance(item, Alt):
return [_ref for _item in item.items for _ref in references_for_item(_item)]
elif isinstance(item, Cut):
return []
elif isinstance(item, Group):
Reported by Pylint.
Line: 58
Column: 1
argparser.add_argument("grammar_file", help="The grammar file to graph")
def references_for_item(item: Any) -> List[Any]:
if isinstance(item, Alt):
return [_ref for _item in item.items for _ref in references_for_item(_item)]
elif isinstance(item, Cut):
return []
elif isinstance(item, Group):
Reported by Pylint.
Line: 58
Column: 1
argparser.add_argument("grammar_file", help="The grammar file to graph")
def references_for_item(item: Any) -> List[Any]:
if isinstance(item, Alt):
return [_ref for _item in item.items for _ref in references_for_item(_item)]
elif isinstance(item, Cut):
return []
elif isinstance(item, Group):
Reported by Pylint.
Tools/freeze/makefreeze.py
12 issues
Line: 32
Column: 22
"""
def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
if entry_point is None: entry_point = default_entry_point
done = []
files = []
mods = sorted(dict.keys())
for mod in mods:
Reported by Pylint.
Line: 46
Column: 17
files.append(file)
if debug:
print("freezing", mod, "...")
str = marshal.dumps(m.__code__)
size = len(str)
if m.__path__:
# Indicate package by negative size
size = -size
done.append((mod, mangled, size))
Reported by Pylint.
Line: 1
Column: 1
import marshal
import bkfile
# Write a file containing frozen code for the modules in the dictionary.
header = """
#include "Python.h"
Reported by Pylint.
Line: 7
Column: 1
# Write a file containing frozen code for the modules in the dictionary.
header = """
#include "Python.h"
static struct _frozen _PyImport_FrozenModules[] = {
"""
trailer = """\
Reported by Pylint.
Line: 12
Column: 1
static struct _frozen _PyImport_FrozenModules[] = {
"""
trailer = """\
{0, 0, 0} /* sentinel */
};
"""
# if __debug__ == 0 (i.e. -O option given), set Py_OptimizeFlag in frozen app.
Reported by Pylint.
Line: 18
Column: 1
"""
# if __debug__ == 0 (i.e. -O option given), set Py_OptimizeFlag in frozen app.
default_entry_point = """
int
main(int argc, char **argv)
{
extern int Py_FrozenMain(int, char **);
""" + ((not __debug__ and """
Reported by Pylint.
Line: 32
Column: 1
"""
def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
if entry_point is None: entry_point = default_entry_point
done = []
files = []
mods = sorted(dict.keys())
for mod in mods:
Reported by Pylint.
Line: 33
Column: 29
"""
def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
if entry_point is None: entry_point = default_entry_point
done = []
files = []
mods = sorted(dict.keys())
for mod in mods:
m = dict[mod]
Reported by Pylint.
Line: 38
Column: 9
files = []
mods = sorted(dict.keys())
for mod in mods:
m = dict[mod]
mangled = "__".join(mod.split("."))
if m.__code__:
file = 'M_' + mangled + '.c'
with bkfile.open(base + file, 'w') as outfp:
files.append(file)
Reported by Pylint.
Line: 77
Column: 1
# Write a C initializer for a module containing the frozen python code.
# The array is called M_<mod>.
def writecode(fp, mod, data):
print('unsigned char M_%s[] = {' % mod, file=fp)
indent = ' ' * 4
for i in range(0, len(data), 16):
print(indent, file=fp, end='')
for c in bytes(data[i:i+16]):
Reported by Pylint.
PC/clinic/winreg.c.h
12 issues
Line: 295
Column: 32
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
static HKEY
winreg_CreateKeyEx_impl(PyObject *module, HKEY key,
const Py_UNICODE *sub_key, int reserved,
REGSAM access);
static PyObject *
winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
Reported by FlawFinder.
Line: 310
Column: 101
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
HKEY _return_value;
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
goto exit;
}
_return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
if (_return_value == NULL) {
goto exit;
Reported by FlawFinder.
Line: 313
Column: 77
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
goto exit;
}
_return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
if (_return_value == NULL) {
goto exit;
}
return_value = PyHKEY_FromHKEY(_return_value);
Reported by FlawFinder.
Line: 418
Column: 59
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
static PyObject *
winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
const Py_UNICODE *sub_key, REGSAM access,
int reserved);
static PyObject *
winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
Reported by FlawFinder.
Line: 433
Column: 86
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
int reserved = 0;
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Converter, &sub_key, &access, &reserved)) {
goto exit;
}
return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
exit:
Reported by FlawFinder.
Line: 436
Column: 66
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Converter, &sub_key, &access, &reserved)) {
goto exit;
}
return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
exit:
/* Cleanup for sub_key */
#if !USE_UNICODE_WCHAR_CACHE
PyMem_Free((void *)sub_key);
Reported by FlawFinder.
Line: 796
Column: 42
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
static HKEY
winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
int reserved, REGSAM access);
static PyObject *
winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
Reported by FlawFinder.
Line: 811
Column: 101
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
HKEY _return_value;
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
goto exit;
}
_return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
if (_return_value == NULL) {
goto exit;
Reported by FlawFinder.
Line: 814
Column: 73
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
clinic_HKEY_converter, &key, _PyUnicode_WideCharString_Opt_Converter, &sub_key, &reserved, &access)) {
goto exit;
}
_return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
if (_return_value == NULL) {
goto exit;
}
return_value = PyHKEY_FromHKEY(_return_value);
Reported by FlawFinder.
Line: 853
Column: 44
CWE codes:
362/367!
Suggestion:
Set up the correct permissions (e.g., using setuid()) and try to open the file directly
static HKEY
winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
int reserved, REGSAM access);
static PyObject *
winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
PyObject *return_value = NULL;
Reported by FlawFinder.
Modules/_decimal/libmpdec/io.c
12 issues
Line: 493
Column: 17
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
if (mpd_isnan(dec)) {
if (mpd_isqnan(dec)) {
strcpy(cp, "NaN");
cp += 3;
}
else {
strcpy(cp, "sNaN");
cp += 4;
Reported by FlawFinder.
Line: 497
Column: 17
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
cp += 3;
}
else {
strcpy(cp, "sNaN");
cp += 4;
}
if (dec->len > 0) { /* diagnostic code */
cp = coeff_to_string(cp, dec);
}
Reported by FlawFinder.
Line: 505
Column: 13
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
}
}
else if (mpd_isinfinite(dec)) {
strcpy(cp, "Infinity");
cp += 8;
}
else { /* debug */
abort(); /* GCOV_NOT_REACHED */
}
Reported by FlawFinder.
Line: 690
Column: 16
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
/* Copy a single UTF-8 char to dest. See: The Unicode Standard, version 5.2,
chapter 3.9: Well-formed UTF-8 byte sequences. */
static int
_mpd_copy_utf8(char dest[5], const char *s)
{
const unsigned char *cp = (const unsigned char *)s;
unsigned char lb, ub;
int count, i;
Reported by FlawFinder.
Line: 1428
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
* denotes the IEEE signal.
*/
static const char *mpd_flag_string[MPD_NUM_FLAGS] = {
"Clamped",
"Conversion_syntax",
"Division_by_zero",
"Division_impossible",
"Division_undefined",
Reported by FlawFinder.
Line: 1446
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
"Underflow",
};
static const char *mpd_signal_string[MPD_NUM_FLAGS] = {
"Clamped",
"IEEE_Invalid_operation",
"Division_by_zero",
"IEEE_Invalid_operation",
"IEEE_Invalid_operation",
Reported by FlawFinder.
Line: 777
Column: 9
CWE codes:
126
}
}
#endif
n = strlen(spec->dot);
if (n == 0 || n > 4) {
return -1;
}
if (strlen(spec->sep) > 4) {
return -1;
Reported by FlawFinder.
Line: 781
Column: 9
CWE codes:
126
if (n == 0 || n > 4) {
return -1;
}
if (strlen(spec->sep) > 4) {
return -1;
}
return 0;
}
Reported by FlawFinder.
Line: 999
Column: 26
CWE codes:
126
int pad = 0;
n_sign = sign ? 1 : 0;
n_sep = (mpd_ssize_t)strlen(spec->sep);
/* Initial write index: set to location of '\0' in the output string.
* Irrelevant for the first run. */
dest->cur = dest->nbytes;
dest->nbytes = dest->nchars = 0;
Reported by FlawFinder.
Line: 1008
Column: 50
CWE codes:
126
_mbstr_copy_ascii(dest, rest, n_rest);
if (dot) {
_mbstr_copy_char(dest, dot, (mpd_ssize_t)strlen(dot));
}
g = spec->grouping;
consume = *g;
while (1) {
Reported by FlawFinder.
Modules/getaddrinfo.c
12 issues
Line: 160
Column: 9
CWE codes:
120
Suggestion:
Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)
#define GET_CANONNAME(ai, str) \
if (pai->ai_flags & AI_CANONNAME) {\
if (((ai)->ai_canonname = (char *)malloc(strlen(str) + 1)) != NULL) {\
strcpy((ai)->ai_canonname, (str));\
} else {\
error = EAI_MEMORY;\
goto free;\
}\
}
Reported by FlawFinder.
Line: 254
Column: 29
CWE codes:
807
20
Suggestion:
Check environment variables carefully before using them
if (firsttime) {
/* translator hack */
{
const char *q = getenv("GAI");
if (q && inet_pton(AF_INET6, q, &faith_prefix) == 1)
translate = YES;
}
firsttime = 0;
}
Reported by FlawFinder.
Line: 173
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (((ai) = (struct addrinfo *)malloc(sizeof(struct addrinfo) +\
((gai_afd)->a_socklen)))\
== NULL) goto free;\
memcpy(ai, pai, sizeof(struct addrinfo));\
(ai)->ai_addr = (struct sockaddr *)((ai) + 1);\
memset((ai)->ai_addr, 0, (gai_afd)->a_socklen);\
(ai)->ai_addr->sa_len = (ai)->ai_addrlen = (gai_afd)->a_socklen;\
(ai)->ai_addr->sa_family = (ai)->ai_family = (gai_afd)->a_af;\
((struct sockinet *)(ai)->ai_addr)->si_port = port;\
Reported by FlawFinder.
Line: 180
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
(ai)->ai_addr->sa_family = (ai)->ai_family = (gai_afd)->a_af;\
((struct sockinet *)(ai)->ai_addr)->si_port = port;\
p = (char *)((ai)->ai_addr);\
memcpy(p + (gai_afd)->a_off, (addr), (gai_afd)->a_addrlen);\
}
#else
#define GET_AI(ai, gai_afd, addr, port) {\
char *p;\
if (((ai) = (struct addrinfo *)malloc(sizeof(struct addrinfo) +\
Reported by FlawFinder.
Line: 188
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
if (((ai) = (struct addrinfo *)malloc(sizeof(struct addrinfo) +\
((gai_afd)->a_socklen)))\
== NULL) goto free;\
memcpy(ai, pai, sizeof(struct addrinfo));\
(ai)->ai_addr = (struct sockaddr *)((ai) + 1);\
memset((ai)->ai_addr, 0, (gai_afd)->a_socklen);\
(ai)->ai_addrlen = (gai_afd)->a_socklen;\
(ai)->ai_addr->sa_family = (ai)->ai_family = (gai_afd)->a_af;\
((struct sockinet *)(ai)->ai_addr)->si_port = port;\
Reported by FlawFinder.
Line: 195
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
(ai)->ai_addr->sa_family = (ai)->ai_family = (gai_afd)->a_af;\
((struct sockinet *)(ai)->ai_addr)->si_port = port;\
p = (char *)((ai)->ai_addr);\
memcpy(p + (gai_afd)->a_off, (addr), (gai_afd)->a_addrlen);\
}
#endif
#define ERR(err) { error = (err); goto bad; }
Reported by FlawFinder.
Line: 243
Column: 5
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
struct addrinfo *top = NULL;
struct addrinfo *cur;
int i, error = 0;
char pton[PTON_MAX];
struct addrinfo ai;
struct addrinfo *pai;
u_short port;
#ifdef FAITH
Reported by FlawFinder.
Line: 295
Column: 9
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
default:
ERR(EAI_FAMILY);
}
memcpy(pai, hints, sizeof(*pai));
switch (pai->ai_socktype) {
case GAI_ANY:
switch (pai->ai_protocol) {
case GAI_ANY:
break;
Reported by FlawFinder.
Line: 342
Column: 35
CWE codes:
190
Suggestion:
If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended)
pai->ai_socktype = SOCK_DGRAM;
pai->ai_protocol = IPPROTO_UDP;
}
port = htons((u_short)atoi(servname));
} else {
struct servent *sp;
const char *proto;
proto = NULL;
Reported by FlawFinder.
Line: 611
Column: 13
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
GET_AI(cur->ai_next, &gai_afdl[N_INET6], ap, port);
in6 = &((struct sockaddr_in6 *)cur->ai_next->ai_addr)->sin6_addr;
memcpy(&in6->s6_addr32[0], &faith_prefix,
sizeof(struct in6_addr) - sizeof(struct in_addr));
memcpy(&in6->s6_addr32[3], ap, sizeof(struct in_addr));
} else
#endif /* FAITH */
GET_AI(cur->ai_next, gai_afd, ap, port);
Reported by FlawFinder.
Modules/_ssl.c
12 issues
Line: 1010
Column: 5
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
static PyObject *
_asn1obj2py(_sslmodulestate *state, const ASN1_OBJECT *name, int no_name)
{
char buf[X509_NAME_MAXLEN];
char *namebuf = buf;
int buflen;
PyObject *name_obj = NULL;
buflen = OBJ_obj2txt(namebuf, X509_NAME_MAXLEN, name, no_name);
Reported by FlawFinder.
Line: 1183
Column: 5
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
GENERAL_NAMES *names = NULL;
GENERAL_NAME *name;
BIO *biobuf = NULL;
char buf[2048];
char *vptr;
int len;
if (certificate == NULL)
return peer_alt_names;
Reported by FlawFinder.
Line: 1327
Column: 27
CWE codes:
120
Suggestion:
Use sprintf_s, snprintf, or vsnprintf
} else if (name->d.ip->length == 16) {
/* PyUnicode_FromFormat() does not support %X */
unsigned char *p = name->d.ip->data;
len = sprintf(
buf,
"%X:%X:%X:%X:%X:%X:%X:%X",
p[0] << 8 | p[1],
p[2] << 8 | p[3],
p[4] << 8 | p[5],
Reported by FlawFinder.
Line: 1559
Column: 5
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
PyObject *sn_obj;
PyObject *obj;
ASN1_INTEGER *serialNumber;
char buf[2048];
int len, result;
const ASN1_TIME *notBefore, *notAfter;
PyObject *pnotBefore, *pnotAfter;
retval = PyDict_New();
Reported by FlawFinder.
Line: 1945
Column: 5
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
unsigned long cipher_id;
int alg_bits, strength_bits, len;
char buf[512] = {0};
int aead, nid;
const char *skcipher = NULL, *digest = NULL, *kx = NULL, *auth = NULL;
/* can be NULL */
cipher_name = SSL_CIPHER_get_name(cipher);
Reported by FlawFinder.
Line: 2693
Column: 5
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
const char *cb_type)
/*[clinic end generated code: output=34bac9acb6a61d31 input=08b7e43b99c17d41]*/
{
char buf[PySSL_CB_MAXLEN];
size_t len;
if (strcmp(cb_type, "tls-unique") == 0) {
if (SSL_session_reused(self->ssl) ^ !self->socket_type) {
/* if session is resumed XOR we are the client */
Reported by FlawFinder.
Line: 3337
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
self->alpn_protocols = PyMem_Malloc(protos->len);
if (!self->alpn_protocols)
return PyErr_NoMemory();
memcpy(self->alpn_protocols, protos->buf, protos->len);
self->alpn_protocols_len = (unsigned int)protos->len;
if (SSL_CTX_set_alpn_protos(self->ctx, self->alpn_protocols, self->alpn_protocols_len))
return PyErr_NoMemory();
SSL_CTX_set_alpn_select_cb(self->ctx, _selectALPN_cb, self);
Reported by FlawFinder.
Line: 3743
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
"unable to allocate password buffer");
goto error;
}
memcpy(pw_info->password, data, size);
pw_info->size = (int)size;
Py_XDECREF(password_bytes);
return 1;
Reported by FlawFinder.
Line: 3791
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
}
PySSL_BEGIN_ALLOW_THREADS_S(pw_info->thread_state);
memcpy(buf, pw_info->password, pw_info->size);
return pw_info->size;
error:
Py_XDECREF(fn_ret);
PySSL_BEGIN_ALLOW_THREADS_S(pw_info->thread_state);
Reported by FlawFinder.
Line: 727
Column: 11
CWE codes:
126
* When name starts with a dot (e.g ".example.com"), it will be
* matched by a certificate valid for any sub-domain of name.
*/
len = strlen(server_hostname);
if (len == 0 || *server_hostname == '.') {
PyErr_SetString(
PyExc_ValueError,
"server_hostname cannot be an empty string or start with a "
"leading dot.");
Reported by FlawFinder.