Skip to content

Commit ba2f30e

Browse files
[3.13] gh-137335: remove a mktemp use in multiprocessing.connection to avoid security scanner noise (GH-148578) (#148584)
gh-137335: remove a mktemp use in multiprocessing.connection to avoid security scanner noise (GH-148578) remove a mktemp use to avoid security scanner noise (cherry picked from commit fd81246) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
1 parent cb4b94c commit ba2f30e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Lib/multiprocessing/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def arbitrary_address(family):
7575
if family == 'AF_INET':
7676
return ('localhost', 0)
7777
elif family == 'AF_UNIX':
78-
return tempfile.mktemp(prefix='sock-', dir=util.get_temp_dir())
78+
# NOTE: util.get_temp_dir() is a 0o700 per-process directory. A
79+
# mktemp-style ToC vs ToU concern is not important; bind() surfaces
80+
# the extremely unlikely collision as EADDRINUSE.
81+
return os.path.join(util.get_temp_dir(),
82+
f'sock-{os.urandom(6).hex()}')
7983
elif family == 'AF_PIPE':
8084
return (r'\\.\pipe\pyc-%d-%d-%s' %
8185
(os.getpid(), next(_mmap_counter), os.urandom(8).hex()))

0 commit comments

Comments
 (0)