The following issues were found

Modules/_io/bytesio.c
3 issues
memcpy - Does not check for buffer overflows when copying to destination
Security

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.

memcpy - Does not check for buffer overflows when copying to destination
Security

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.

memcpy - Does not check for buffer overflows when copying to destination
Security

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
strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

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.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

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.

strlen - Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected)
Security

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
Module 'signal' has no 'CTRL_C_EVENT' member
Error

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.

Module 'signal' has no 'CTRL_BREAK_EVENT' member
Error

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.

Consider using sys.exit()
Error

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
Missing module docstring
Error

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.

Missing function or method docstring
Error

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.

Missing function or method docstring
Error

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
Attempted relative import beyond top-level package
Error

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.

Attempted relative import beyond top-level package
Error

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.

Missing function or method docstring
Error

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
Attempted relative import beyond top-level package
Error

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.

Missing module docstring
Error

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.

Import outside toplevel (_delim.parse)
Error

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
Dangerous assignment - the function parameter is assigned the address of a local auto-variable. Local auto-variables are reserved from the stack which is freed when the function ends. So the pointer to a local variable is invalid after the function ends.
Error

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.

Possible null pointer dereference: args
Error

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.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

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
Attempted relative import beyond top-level package
Error

Line: 1 Column: 1

              from . import basic

            

Reported by Pylint.

Unused import basic
Error

Line: 1 Column: 1

              from . import basic

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from . import basic

            

Reported by Pylint.

Lib/test/libregrtest/pgo.py
3 issues
Missing module docstring
Error

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.

Argument name "ns" doesn't conform to snake_case naming style
Error

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.

Missing function or method docstring
Error

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
Attempted relative import beyond top-level package
Error

Line: 1 Column: 1

              from . import source
source.spam

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 2 Column: 1

              from . import source
source.spam

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from . import source
source.spam

            

Reported by Pylint.