@@ -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
136138if sys .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 path length(without NULL terminator) will be:
175177#
176178# len(base_tempdir + '/pymp-XXXXXXXX' + '/sock-XXXXXXXX')
177179sun_path_len = len (base_tempdir )+ 14 + 14
178- if sun_path_len <= _SUN_PATH_MAX :
180+ # Strict inequality to account for the NULL terminator.
181+ # See https://github.com/python/cpython/issues/140734.
182+ if sun_path_len < _SUN_PATH_MAX :
179183return base_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):
201205return base_tempdir
202206warn ("Ignoring user-defined temporary directory: %s" ,base_tempdir )
203207# at most max(map(len, dirlist)) + 14 + 14 = 36 characters
204- assert len (base_system_tempdir )+ 14 + 14 <= _SUN_PATH_MAX
208+ assert len (base_system_tempdir )+ 14 + 14 < _SUN_PATH_MAX
205209return base_system_tempdir
206210
207211def get_temp_dir ():