]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-137335: remove a mktemp use in multiprocessing.connection to avoid security scanne...
authorGregory P. Smith <68491+gpshead@users.noreply.github.com>
Tue, 14 Apr 2026 23:31:58 +0000 (16:31 -0700)
committerGitHub <noreply@github.com>
Tue, 14 Apr 2026 23:31:58 +0000 (23:31 +0000)
remove a mktemp use to avoid security scanner noise

Lib/multiprocessing/connection.py

index 9ce996c9ccd2116f03f7061cfd9a985adbe19e87..e37ec07d722ca860c9a842f678fa1425a7565e57 100644 (file)
@@ -16,7 +16,6 @@ import os
 import sys
 import socket
 import struct
-import tempfile
 import time
 
 
@@ -77,7 +76,11 @@ def arbitrary_address(family):
     if family == 'AF_INET':
         return ('localhost', 0)
     elif family == 'AF_UNIX':
-        return tempfile.mktemp(prefix='sock-', dir=util.get_temp_dir())
+        # NOTE: util.get_temp_dir() is a 0o700 per-process directory. A
+        # mktemp-style ToC vs ToU concern is not important; bind() surfaces
+        # the extremely unlikely collision as EADDRINUSE.
+        return os.path.join(util.get_temp_dir(),
+                            f'sock-{os.urandom(6).hex()}')
     elif family == 'AF_PIPE':
         return (r'\\.\pipe\pyc-%d-%d-%s' %
                 (os.getpid(), next(_mmap_counter), os.urandom(8).hex()))