The following issues were found
Modules/_io/bytesio.c
3 issues
Line: 115
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
new_buf = PyBytes_FromStringAndSize(NULL, size);
if (new_buf == NULL)
return -1;
memcpy(PyBytes_AS_STRING(new_buf), PyBytes_AS_STRING(self->buf),
self->string_size);
Py_SETREF(self->buf, new_buf);
return 0;
}
Reported by FlawFinder.
Line: 228
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
/* Copy the data to the internal buffer, overwriting some of the existing
data if self->pos < self->string_size. */
memcpy(PyBytes_AS_STRING(self->buf) + self->pos, buf.buf, len);
self->pos = endpos;
/* Set the new length of the internal string if it has changed. */
if ((size_t)self->string_size < endpos) {
self->string_size = endpos;
Reported by FlawFinder.
Line: 580
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
len = 0;
}
memcpy(buffer->buf, PyBytes_AS_STRING(self->buf) + self->pos, len);
assert(self->pos + len < PY_SSIZE_T_MAX);
assert(len >= 0);
self->pos += len;
return PyLong_FromSsize_t(len);
Reported by FlawFinder.
Objects/clinic/floatobject.c.h
3 issues
Line: 282
Column: 9
CWE codes:
126
if (typestr == NULL) {
goto exit;
}
if (strlen(typestr) != (size_t)typestr_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
return_value = float___getformat___impl(type, typestr);
Reported by FlawFinder.
Line: 336
Column: 9
CWE codes:
126
if (typestr == NULL) {
goto exit;
}
if (strlen(typestr) != (size_t)typestr_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
if (!PyUnicode_Check(args[1])) {
_PyArg_BadArgument("__set_format__", "argument 2", "str", args[1]);
Reported by FlawFinder.
Line: 349
Column: 9
CWE codes:
126
if (fmt == NULL) {
goto exit;
}
if (strlen(fmt) != (size_t)fmt_length) {
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
return_value = float___set_format___impl(type, typestr, fmt);
Reported by FlawFinder.
Lib/test/win_console_handler.py
3 issues
Line: 22
Column: 15
def _ctrl_handler(sig):
"""Handle a sig event and return 0 to terminate the process"""
if sig == signal.CTRL_C_EVENT:
pass
elif sig == signal.CTRL_BREAK_EVENT:
pass
else:
print("UNKNOWN EVENT")
Reported by Pylint.
Line: 24
Column: 17
"""Handle a sig event and return 0 to terminate the process"""
if sig == signal.CTRL_C_EVENT:
pass
elif sig == signal.CTRL_BREAK_EVENT:
pass
else:
print("UNKNOWN EVENT")
return 0
Reported by Pylint.
Line: 41
Column: 9
# Add our console control handling function with value 1
if not SetConsoleCtrlHandler(ctrl_handler, 1):
print("Unable to add SetConsoleCtrlHandler")
exit(-1)
# Awake main process
m = mmap.mmap(-1, 1, sys.argv[1])
m[0] = 1
Reported by Pylint.
Lib/test/test_unittest.py
3 issues
Line: 1
Column: 1
import unittest.test
from test import support
def test_main():
# used by regrtest
support.run_unittest(unittest.test.suite())
support.reap_children()
Reported by Pylint.
Line: 6
Column: 1
from test import support
def test_main():
# used by regrtest
support.run_unittest(unittest.test.suite())
support.reap_children()
def load_tests(*_):
Reported by Pylint.
Line: 11
Column: 1
support.run_unittest(unittest.test.suite())
support.reap_children()
def load_tests(*_):
# used by unittest
return unittest.test.suite()
if __name__ == "__main__":
test_main()
Reported by Pylint.
Tools/peg_generator/pegen/keywordgen.py
3 issues
Line: 5
Column: 1
import argparse
from .build import build_parser, generate_token_definitions
from .c_generator import CParserGenerator
TEMPLATE = r'''
"""Keywords (from "Grammar/python.gram")
Reported by Pylint.
Line: 6
Column: 1
import argparse
from .build import build_parser, generate_token_definitions
from .c_generator import CParserGenerator
TEMPLATE = r'''
"""Keywords (from "Grammar/python.gram")
This file is automatically generated; please don't muck it up!
Reported by Pylint.
Line: 41
Column: 1
EXTRA_KEYWORDS = ["async", "await"]
def main() -> None:
parser = argparse.ArgumentParser(
description="Generate the Lib/keywords.py file from the grammar."
)
parser.add_argument(
"grammar", type=str, help="The file with the grammar definition in PEG format"
Reported by Pylint.
Tools/c-analyzer/c_parser/parser/_alt.py
3 issues
Line: 5
Column: 5
def _parse(srclines, anon_name):
text = ' '.join(l for _, l in srclines)
from ._delim import parse
yield from parse(text, anon_name)
Reported by Pylint.
Line: 1
Column: 1
def _parse(srclines, anon_name):
text = ' '.join(l for _, l in srclines)
from ._delim import parse
yield from parse(text, anon_name)
Reported by Pylint.
Line: 5
Column: 5
def _parse(srclines, anon_name):
text = ' '.join(l for _, l in srclines)
from ._delim import parse
yield from parse(text, anon_name)
Reported by Pylint.
Python/ceval.c
3 issues
Line: 1533
CWE codes:
562
CFrame *prev_cframe = tstate->cframe;
cframe.use_tracing = prev_cframe->use_tracing;
cframe.previous = prev_cframe;
tstate->cframe = &cframe;
/* push frame */
tstate->frame = frame;
if (cframe.use_tracing) {
Reported by Cppcheck.
Line: 5235
CWE codes:
476
n = argcount;
}
for (j = 0; j < n; j++) {
PyObject *x = args[j];
Py_INCREF(x);
SETLOCAL(j, x);
}
/* Pack other positional arguments into the *args argument */
Reported by Cppcheck.
Line: 2660
Column: 34
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
"Illegal kind for GEN_START");
}
else {
static const char *gen_kind[3] = {
"generator",
"coroutine",
"async generator"
};
_PyErr_Format(tstate, PyExc_TypeError,
Reported by FlawFinder.
Lib/test/test_import/data/circular_imports/basic2.py
3 issues
Line: 1
Column: 1
from . import basic
Reported by Pylint.
Line: 1
Column: 1
from . import basic
Reported by Pylint.
Line: 1
Column: 1
from . import basic
Reported by Pylint.
Lib/test/libregrtest/pgo.py
3 issues
Line: 1
Column: 1
# Set of tests run by default if --pgo is specified. The tests below were
# chosen based on the following criteria: either they exercise a commonly used
# C extension module or type, or they run some relatively typical Python code.
# Long running tests should be avoided because the PGO instrumented executable
# runs slowly.
PGO_TESTS = [
'test_array',
'test_base64',
'test_binascii',
Reported by Pylint.
Line: 53
Column: 1
'test_xml_etree_c',
]
def setup_pgo_tests(ns):
if not ns.args and not ns.pgo_extended:
# run default set of tests for PGO training
ns.args = PGO_TESTS[:]
Reported by Pylint.
Line: 53
Column: 1
'test_xml_etree_c',
]
def setup_pgo_tests(ns):
if not ns.args and not ns.pgo_extended:
# run default set of tests for PGO training
ns.args = PGO_TESTS[:]
Reported by Pylint.
Lib/test/test_import/data/circular_imports/use.py
3 issues
Line: 1
Column: 1
from . import source
source.spam
Reported by Pylint.
Line: 2
Column: 1
from . import source
source.spam
Reported by Pylint.
Line: 1
Column: 1
from . import source
source.spam
Reported by Pylint.