The following issues were found

Tools/scripts/run_tests.py
7 issues
Missing function or method docstring
Error

Line: 15 Column: 1

              import test.support


def is_multiprocess_flag(arg):
    return arg.startswith('-j') or arg.startswith('--multiprocess')


def is_resource_use_flag(arg):
    return arg.startswith('-u') or arg.startswith('--use')

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

                  return arg.startswith('-j') or arg.startswith('--multiprocess')


def is_resource_use_flag(arg):
    return arg.startswith('-u') or arg.startswith('--use')


def main(regrtest_args):
    args = [sys.executable,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

                  return arg.startswith('-u') or arg.startswith('--use')


def main(regrtest_args):
    args = [sys.executable,
            '-u',                 # Unbuffered stdout and stderr
            '-W', 'default',      # Warnings set to 'default'
            '-bb',                # Warnings about bytes/bytearray
            '-E',                 # Ignore environment variables

            

Reported by Pylint.

Import outside toplevel (subprocess.call)
Error

Line: 47 Column: 9

                  args.extend(regrtest_args)
    print(' '.join(args))
    if sys.platform == 'win32':
        from subprocess import call
        sys.exit(call(args))
    else:
        os.execv(sys.executable, args)



            

Reported by Pylint.

Consider possible security implications associated with call module.
Security blacklist

Line: 47
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

                  args.extend(regrtest_args)
    print(' '.join(args))
    if sys.platform == 'win32':
        from subprocess import call
        sys.exit(call(args))
    else:
        os.execv(sys.executable, args)



            

Reported by Bandit.

subprocess call - check for execution of untrusted input.
Security injection

Line: 48
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

                  print(' '.join(args))
    if sys.platform == 'win32':
        from subprocess import call
        sys.exit(call(args))
    else:
        os.execv(sys.executable, args)


if __name__ == '__main__':

            

Reported by Bandit.

Starting a process without a shell.
Security injection

Line: 50
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b606_start_process_with_no_shell.html

                      from subprocess import call
        sys.exit(call(args))
    else:
        os.execv(sys.executable, args)


if __name__ == '__main__':
    main(sys.argv[1:])

            

Reported by Bandit.

Tools/unicode/listcodecs.py
7 issues
Redefining built-in 'dir'
Error

Line: 13 Column: 16

              
_debug = 0

def listcodecs(dir):
    names = []
    for filename in os.listdir(dir):
        if filename[-3:] != '.py':
            continue
        name = filename[:-3]

            

Reported by Pylint.

Redefining name 'names' from outer scope (line 36)
Error

Line: 14 Column: 5

              _debug = 0

def listcodecs(dir):
    names = []
    for filename in os.listdir(dir):
        if filename[-3:] != '.py':
            continue
        name = filename[:-3]
        # Check whether we've found a true codec

            

Reported by Pylint.

Redefining name 'name' from outer scope (line 39)
Error

Line: 18 Column: 9

                  for filename in os.listdir(dir):
        if filename[-3:] != '.py':
            continue
        name = filename[:-3]
        # Check whether we've found a true codec
        try:
            codecs.lookup(name)
        except LookupError:
            # Codec not found

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 25 Column: 16

                      except LookupError:
            # Codec not found
            continue
        except Exception as reason:
            # Probably an error from importing the codec; still it's
            # a valid code name
            if _debug:
                print('* problem importing codec %r: %s' % \
                      (name, reason))

            

Reported by Pylint.

Multiple imports on one line (os, codecs, encodings)
Error

Line: 9 Column: 1

              
"""

import os, codecs, encodings

_debug = 0

def listcodecs(dir):
    names = []

            

Reported by Pylint.

Constant name "_debug" doesn't conform to UPPER_CASE naming style
Error

Line: 11 Column: 1

              
import os, codecs, encodings

_debug = 0

def listcodecs(dir):
    names = []
    for filename in os.listdir(dir):
        if filename[-3:] != '.py':

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              
_debug = 0

def listcodecs(dir):
    names = []
    for filename in os.listdir(dir):
        if filename[-3:] != '.py':
            continue
        name = filename[:-3]

            

Reported by Pylint.

Tools/unicode/genmap_korean.py
7 issues
Unused import BufferedFiller from wildcard import
Error

Line: 9 Column: 1

              #
import os

from genmap_support import *


KSX1001_C1 = (0x21, 0x7e)
KSX1001_C2 = (0x21, 0x7e)
UHCL1_C1 = (0x81, 0xa0)

            

Reported by Pylint.

Wildcard import genmap_support
Error

Line: 9 Column: 1

              #
import os

from genmap_support import *


KSX1001_C1 = (0x21, 0x7e)
KSX1001_C2 = (0x21, 0x7e)
UHCL1_C1 = (0x81, 0xa0)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #
# genmap_korean.py: Korean Codecs Map Generator
#
# Original Author:  Hye-Shik Chang <perky@FreeBSD.org>
# Modified Author:  Dong-hee Na <donghee.na92@gmail.com>
#
import os

from genmap_support import *

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 1

              MAPPINGS_CP949 = 'http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP949.TXT'


def main():
    mapfile = open_mapping_file('python-mappings/CP949.TXT', MAPPINGS_CP949)
    print("Loading Mapping File...")
    decmap = loadmap(mapfile)
    uhcdecmap, ksx1001decmap, cp949encmap = {}, {}, {}
    for c1, c2map in decmap.items():

            

Reported by Pylint.

Variable name "c1" doesn't conform to snake_case naming style
Error

Line: 26 Column: 9

                  print("Loading Mapping File...")
    decmap = loadmap(mapfile)
    uhcdecmap, ksx1001decmap, cp949encmap = {}, {}, {}
    for c1, c2map in decmap.items():
        for c2, code in c2map.items():
            if c1 >= 0xa1 and c2 >= 0xa1:
                ksx1001decmap.setdefault(c1 & 0x7f, {})
                ksx1001decmap[c1 & 0x7f][c2 & 0x7f] = c2map[c2]
                cp949encmap.setdefault(code >> 8, {})

            

Reported by Pylint.

Variable name "c2" doesn't conform to snake_case naming style
Error

Line: 27 Column: 13

                  decmap = loadmap(mapfile)
    uhcdecmap, ksx1001decmap, cp949encmap = {}, {}, {}
    for c1, c2map in decmap.items():
        for c2, code in c2map.items():
            if c1 >= 0xa1 and c2 >= 0xa1:
                ksx1001decmap.setdefault(c1 & 0x7f, {})
                ksx1001decmap[c1 & 0x7f][c2 & 0x7f] = c2map[c2]
                cp949encmap.setdefault(code >> 8, {})
                cp949encmap[code >> 8][code & 0xFF] = (c1 << 8 | c2) & 0x7f7f

            

Reported by Pylint.

Variable name "fp" doesn't conform to snake_case naming style
Error

Line: 40 Column: 40

                              cp949encmap.setdefault(code >> 8, {})  # MSB set
                cp949encmap[code >> 8][code & 0xFF] = (c1 << 8 | c2)

    with open('mappings_kr.h', 'w') as fp:
        print_autogen(fp, os.path.basename(__file__))

        print("Generating KS X 1001 decode map...")
        writer = DecodeMapWriter(fp, "ksx1001", ksx1001decmap)
        writer.update_decode_map(KSX1001_C1, KSX1001_C2)

            

Reported by Pylint.

Tools/scripts/make_ctype.py
7 issues
Cell variable c defined in loop
Error

Line: 24 Column: 45

                      if name in ("ALPHA", "ALNUM"):
            continue
        if name == "XDIGIT":
            method = lambda: c.isdigit() or c.upper() in "ABCDEF"
        else:
            method = getattr(c, "is" + name.lower())
        if method():
            flags.append("FLAG_" + name)
    rc = repr(c)

            

Reported by Pylint.

Cell variable c defined in loop
Error

Line: 24 Column: 30

                      if name in ("ALPHA", "ALNUM"):
            continue
        if name == "XDIGIT":
            method = lambda: c.isdigit() or c.upper() in "ABCDEF"
        else:
            method = getattr(c, "is" + name.lower())
        if method():
            flags.append("FLAG_" + name)
    rc = repr(c)

            

Reported by Pylint.

Redefining name 'i' from outer scope (line 59)
Error

Line: 61 Column: 5

              
for i in range(0, 256, 8):
    values = []
    for i in range(i, i+8):
        if i < 128:
            c = chr(i)
            if c.isupper():
                i = ord(c.lower())
        values.append("0x%02x" % i)

            

Reported by Pylint.

Redefining name 'i' from outer scope (line 74)
Error

Line: 76 Column: 5

              
for i in range(0, 256, 8):
    values = []
    for i in range(i, i+8):
        if i < 128:
            c = chr(i)
            if c.islower():
                i = ord(c.upper())
        values.append("0x%02x" % i)

            

Reported by Pylint.

Constant name "rc" doesn't conform to UPPER_CASE naming style
Error

Line: 31 Column: 9

                          flags.append("FLAG_" + name)
    rc = repr(c)
    if c == '\v':
        rc = "'\\v'"
    elif c == '\f':
        rc = "'\\f'"
    if not flags:
        print("    0, /* 0x%x %s */" % (i, rc))
    else:

            

Reported by Pylint.

Constant name "rc" doesn't conform to UPPER_CASE naming style
Error

Line: 33 Column: 9

                  if c == '\v':
        rc = "'\\v'"
    elif c == '\f':
        rc = "'\\f'"
    if not flags:
        print("    0, /* 0x%x %s */" % (i, rc))
    else:
        print("    %s, /* 0x%x %s */" % ("|".join(flags), i, rc))


            

Reported by Pylint.

Constant name "name" doesn't conform to UPPER_CASE naming style
Error

Line: 52 Column: 5

              print("")

for name in NAMES:
    name = "is" + name.lower()
    print("#undef %s" % name)
    print("#define %s(c) undefined_%s(c)" % (name, name))

print("""
static unsigned char ctype_tolower[256] = {""")

            

Reported by Pylint.

Tools/scripts/lll.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              #! /usr/bin/env python3

# Find symbolic links and show where they point to.
# Arguments are directories to search; default is current directory.
# No recursion.
# (This is a totally different program from "findsymlinks.py"!)

import sys, os


            

Reported by Pylint.

Multiple imports on one line (sys, os)
Error

Line: 8 Column: 1

              # No recursion.
# (This is a totally different program from "findsymlinks.py"!)

import sys, os

def lll(dirname):
    for name in os.listdir(dirname):
        if name not in (os.curdir, os.pardir):
            full = os.path.join(dirname, name)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

              
import sys, os

def lll(dirname):
    for name in os.listdir(dirname):
        if name not in (os.curdir, os.pardir):
            full = os.path.join(dirname, name)
            if os.path.islink(full):
                print(name, '->', os.readlink(full))

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

                          full = os.path.join(dirname, name)
            if os.path.islink(full):
                print(name, '->', os.readlink(full))
def main(args):
    if not args: args = [os.curdir]
    first = 1
    for arg in args:
        if len(args) > 1:
            if not first: print()

            

Reported by Pylint.

More than one statement on a single line
Error

Line: 17 Column: 18

                          if os.path.islink(full):
                print(name, '->', os.readlink(full))
def main(args):
    if not args: args = [os.curdir]
    first = 1
    for arg in args:
        if len(args) > 1:
            if not first: print()
            first = 0

            

Reported by Pylint.

More than one statement on a single line
Error

Line: 21 Column: 27

                  first = 1
    for arg in args:
        if len(args) > 1:
            if not first: print()
            first = 0
            print(arg + ':')
        lll(arg)

if __name__ == '__main__':

            

Reported by Pylint.

Tools/scripts/fixheader.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              #! /usr/bin/env python3

# Add some standard cpp magic to a header file

import sys

def main():
    args = sys.argv[1:]
    for filename in args:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              
import sys

def main():
    args = sys.argv[1:]
    for filename in args:
        process(filename)

def process(filename):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

                  for filename in args:
        process(filename)

def process(filename):
    try:
        f = open(filename, 'r')
    except IOError as msg:
        sys.stderr.write('%s: can\'t open: %s\n' % (filename, str(msg)))
        return

            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 14 Column: 9

              
def process(filename):
    try:
        f = open(filename, 'r')
    except IOError as msg:
        sys.stderr.write('%s: can\'t open: %s\n' % (filename, str(msg)))
        return
    with f:
        data = f.read()

            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 24 Column: 9

                      sys.stderr.write('%s does not begin with C comment\n' % filename)
        return
    try:
        f = open(filename, 'w')
    except IOError as msg:
        sys.stderr.write('%s: can\'t write: %s\n' % (filename, str(msg)))
        return
    with f:
        sys.stderr.write('Processing %s ...\n' % filename)

            

Reported by Pylint.

Variable name "c" doesn't conform to snake_case naming style
Error

Line: 31 Column: 13

                  with f:
        sys.stderr.write('Processing %s ...\n' % filename)
        magic = 'Py_'
        for c in filename:
            if ord(c)<=0x80 and c.isalnum():
                magic = magic + c.upper()
            else: magic = magic + '_'
        print('#ifndef', magic, file=f)
        print('#define', magic, file=f)

            

Reported by Pylint.

Lib/venv/__main__.py
6 issues
Attempted relative import beyond top-level package
Error

Line: 2 Column: 1

              import sys
from . import main

rc = 1
try:
    main()
    rc = 0
except Exception as e:
    print('Error: %s' % e, file=sys.stderr)

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 8 Column: 8

              try:
    main()
    rc = 0
except Exception as e:
    print('Error: %s' % e, file=sys.stderr)
sys.exit(rc)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import sys
from . import main

rc = 1
try:
    main()
    rc = 0
except Exception as e:
    print('Error: %s' % e, file=sys.stderr)

            

Reported by Pylint.

Constant name "rc" doesn't conform to UPPER_CASE naming style
Error

Line: 4 Column: 1

              import sys
from . import main

rc = 1
try:
    main()
    rc = 0
except Exception as e:
    print('Error: %s' % e, file=sys.stderr)

            

Reported by Pylint.

Constant name "rc" doesn't conform to UPPER_CASE naming style
Error

Line: 7 Column: 5

              rc = 1
try:
    main()
    rc = 0
except Exception as e:
    print('Error: %s' % e, file=sys.stderr)
sys.exit(rc)

            

Reported by Pylint.

Variable name "e" doesn't conform to snake_case naming style
Error

Line: 8 Column: 1

              try:
    main()
    rc = 0
except Exception as e:
    print('Error: %s' % e, file=sys.stderr)
sys.exit(rc)

            

Reported by Pylint.

Lib/test/test_xmlrpc_net.py
6 issues
Lambda may not be necessary
Error

Line: 19 Column: 25

                          builders = server.getAllBuilders()
        except OSError as e:
            self.skipTest("network error: %s" % e)
        self.addCleanup(lambda: server('close')())

        # Perform a minimal sanity check on the result, just to be sure
        # the request means what we think it means.
        self.assertIsInstance(builders, collections.abc.Sequence)
        self.assertTrue([x for x in builders if "3.x" in x], builders)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import collections.abc
import unittest
from test import support

import xmlrpc.client as xmlrpclib


@unittest.skip('XXX: buildbot.python.org/all/xmlrpc/ is gone')
class PythonBuildersTest(unittest.TestCase):

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              

@unittest.skip('XXX: buildbot.python.org/all/xmlrpc/ is gone')
class PythonBuildersTest(unittest.TestCase):

    def test_python_builders(self):
        # Get the list of builders from the XMLRPC buildbot interface at
        # python.org.
        server = xmlrpclib.ServerProxy("http://buildbot.python.org/all/xmlrpc/")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 5

              @unittest.skip('XXX: buildbot.python.org/all/xmlrpc/ is gone')
class PythonBuildersTest(unittest.TestCase):

    def test_python_builders(self):
        # Get the list of builders from the XMLRPC buildbot interface at
        # python.org.
        server = xmlrpclib.ServerProxy("http://buildbot.python.org/all/xmlrpc/")
        try:
            builders = server.getAllBuilders()

            

Reported by Pylint.

Variable name "e" doesn't conform to snake_case naming style
Error

Line: 17 Column: 9

                      server = xmlrpclib.ServerProxy("http://buildbot.python.org/all/xmlrpc/")
        try:
            builders = server.getAllBuilders()
        except OSError as e:
            self.skipTest("network error: %s" % e)
        self.addCleanup(lambda: server('close')())

        # Perform a minimal sanity check on the result, just to be sure
        # the request means what we think it means.

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

                      self.assertTrue([x for x in builders if "3.x" in x], builders)


def test_main():
    support.requires("network")
    support.run_unittest(PythonBuildersTest)

if __name__ == "__main__":
    test_main()

            

Reported by Pylint.

Modules/_ctypes/darwin/dlfcn_simple.c
6 issues
vsnprintf - If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate
Security

Line: 92 Column: 9 CWE codes: 134
Suggestion: Use a constant for the format specification

                  {
        va_start(arg, str);
        strncpy(errstr, "dlcompat: ", ERR_STR_LEN);
        vsnprintf(errstr + 10, ERR_STR_LEN - 10, str, arg);
        va_end(arg);
        err_filled = 1;
        retval = NULL;
    }
    else

            

Reported by FlawFinder.

sprintf - Does not check for buffer overflows
Security

Line: 231 Column: 13 CWE codes: 120
Suggestion: Use sprintf_s, snprintf, or vsnprintf

                      malloc_sym = malloc(sym_len + 2);
        if (malloc_sym)
        {
            sprintf(malloc_sym, "_%s", symbol);
            value = dlsymIntern(handle, malloc_sym);
            free(malloc_sym);
        }
        else
        {

            

Reported by FlawFinder.

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

Line: 84 Column: 12 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

              /* Set and get the error string for use by dlerror */
static const char *error(int setget, const char *str, ...)
{
    static char errstr[ERR_STR_LEN];
    static int err_filled = 0;
    const char *retval;
    va_list arg;
    if (setget == 0)
    {

            

Reported by FlawFinder.

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

Line: 216 Column: 12 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

              /* dlsym, prepend the underscore and call dlsymIntern */
static void *darwin_dlsym(void *handle, const char *symbol)
{
    static char undersym[257];          /* Saves calls to malloc(3) */
    int sym_len = strlen(symbol);
    void *value = NULL;
    char *malloc_sym = NULL;

    if (sym_len < 256)

            

Reported by FlawFinder.

strncpy - Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned]
Security

Line: 91 Column: 9 CWE codes: 120

                  if (setget == 0)
    {
        va_start(arg, str);
        strncpy(errstr, "dlcompat: ", ERR_STR_LEN);
        vsnprintf(errstr + 10, ERR_STR_LEN - 10, str, arg);
        va_end(arg);
        err_filled = 1;
        retval = NULL;
    }

            

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: 217 Column: 19 CWE codes: 126

              static void *darwin_dlsym(void *handle, const char *symbol)
{
    static char undersym[257];          /* Saves calls to malloc(3) */
    int sym_len = strlen(symbol);
    void *value = NULL;
    char *malloc_sym = NULL;

    if (sym_len < 256)
    {

            

Reported by FlawFinder.

Tools/freeze/regen_frozen.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3
import sys
import os
import marshal


DIR = os.path.dirname(sys.argv[0])
# source code for module to freeze
FILE = os.path.join(DIR, 'flag.py')

            

Reported by Pylint.

Variable name "fp" doesn't conform to snake_case naming style
Error

Line: 18 Column: 33

                  """Compile 'filename' and return the module code as a marshalled byte
    string.
    """
    with open(filename, 'r') as fp:
        src = fp.read()
    co = compile(src, 'none', 'exec')
    co_bytes = marshal.dumps(co)
    return co_bytes


            

Reported by Pylint.

Variable name "co" doesn't conform to snake_case naming style
Error

Line: 20 Column: 5

                  """
    with open(filename, 'r') as fp:
        src = fp.read()
    co = compile(src, 'none', 'exec')
    co_bytes = marshal.dumps(co)
    return co_bytes


def gen_c_code(fp, co_bytes):

            

Reported by Pylint.

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

Line: 25 Column: 1

                  return co_bytes


def gen_c_code(fp, co_bytes):
    """Generate C code for the module code in 'co_bytes', write it to 'fp'.
    """
    def write(*args, **kwargs):
        print(*args, **kwargs, file=fp)
    write('/* Generated with Tools/freeze/regen_frozen.py */')

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 43 Column: 1

                  write('};')


def main():
    out_filename = sys.argv[1]
    co_bytes = get_module_code(FILE)
    with open(out_filename, 'w') as fp:
        gen_c_code(fp, co_bytes)


            

Reported by Pylint.

Variable name "fp" doesn't conform to snake_case naming style
Error

Line: 46 Column: 37

              def main():
    out_filename = sys.argv[1]
    co_bytes = get_module_code(FILE)
    with open(out_filename, 'w') as fp:
        gen_c_code(fp, co_bytes)


if __name__ == '__main__':
    main()

            

Reported by Pylint.