Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a19900

Browse files
authored
gh-140734: fix off-by-one error when comparing to_SUN_PATH_MAX (#140903)
The limit includes a NULL terminator.
1 parentc77441e commit9a19900

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

‎Lib/multiprocessing/util.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ def is_abstract_socket_namespace(address):
126126
# Function returning a temp directory which will be removed on exit
127127
#
128128

129-
# Maximum length of a socket file path is usually between 92 and 108 [1],
130-
# but Linux is known to use a size of 108 [2]. BSD-based systems usually
131-
# use a size of 104 or 108 and Windows does not create AF_UNIX sockets.
129+
# Maximum length of a NULL-terminated [1] socket file path is usually
130+
# between 92 and 108 [2], but Linux is known to use a size of 108 [3].
131+
# BSD-based systems usually use a size of 104 or 108 and Windows does
132+
# not create AF_UNIX sockets.
132133
#
133-
# [1]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_un.h.html
134-
# [2]: https://man7.org/linux/man-pages/man7/unix.7.html.
134+
# [1]: https://github.com/python/cpython/issues/140734
135+
# [2]: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_un.h.html
136+
# [3]: https://man7.org/linux/man-pages/man7/unix.7.html
135137

136138
ifsys.platform=='linux':
137139
_SUN_PATH_MAX=108
@@ -171,11 +173,13 @@ def _get_base_temp_dir(tempfile):
171173
# generated by tempfile._RandomNameSequence, which, by design,
172174
# is 8 characters long.
173175
#
174-
# Thus, the lengthof socket filename will be:
176+
# Thus, thesocket file pathlength(without NULL terminator) will be:
175177
#
176178
# len(base_tempdir + '/pymp-XXXXXXXX' + '/sock-XXXXXXXX')
177179
sun_path_len=len(base_tempdir)+14+14
178-
ifsun_path_len<=_SUN_PATH_MAX:
180+
# Strict inequality to account for the NULL terminator.
181+
# See https://github.com/python/cpython/issues/140734.
182+
ifsun_path_len<_SUN_PATH_MAX:
179183
returnbase_tempdir
180184
# Fallback to the default system-wide temporary directory.
181185
# This ignores user-defined environment variables.
@@ -201,7 +205,7 @@ def _get_base_temp_dir(tempfile):
201205
returnbase_tempdir
202206
warn("Ignoring user-defined temporary directory: %s",base_tempdir)
203207
# at most max(map(len, dirlist)) + 14 + 14 = 36 characters
204-
assertlen(base_system_tempdir)+14+14<=_SUN_PATH_MAX
208+
assertlen(base_system_tempdir)+14+14<_SUN_PATH_MAX
205209
returnbase_system_tempdir
206210

207211
defget_temp_dir():
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`multiprocessing`: fix off-by-one error when checking the length
2+
of a temporary socket file path. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp