[3.11] gh-104522: Fix OSError raised when run a subprocess (GH-114195) (GH-114243)

Only set filename to cwd if it was caused by failed chdir(cwd).

_fork_exec() now returns "noexec:chdir" for failed chdir(cwd).

(cherry picked from commit e2c097ebde)

Co-authored-by: Robert O'Shea <PurityLake@users.noreply.github.com>
This commit is contained in:
Serhiy Storchaka 2024-01-18 13:32:57 +02:00 committed by GitHub
parent 9887b0c396
commit 2c9872428e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 17 deletions

View file

@ -2030,11 +2030,12 @@ class POSIXProcessTestCase(BaseTestCase):
"import os; print(os.getuid())"],
user=user,
close_fds=close_fds)
except PermissionError: # (EACCES, EPERM)
pass
except PermissionError as e: # (EACCES, EPERM)
self.assertIsNone(e.filename)
except OSError as e:
if e.errno not in (errno.EACCES, errno.EPERM):
raise
self.assertIsNone(e.filename)
else:
if isinstance(user, str):
user_uid = pwd.getpwnam(user).pw_uid
@ -2078,8 +2079,8 @@ class POSIXProcessTestCase(BaseTestCase):
"import os; print(os.getgid())"],
group=group,
close_fds=close_fds)
except PermissionError: # (EACCES, EPERM)
pass
except PermissionError as e: # (EACCES, EPERM)
self.assertIsNone(e.filename)
else:
if isinstance(group, str):
group_gid = grp.getgrnam(group).gr_gid
@ -2124,6 +2125,7 @@ class POSIXProcessTestCase(BaseTestCase):
except OSError as ex:
if ex.errno != errno.EPERM:
raise
self.assertIsNone(ex.filename)
perm_error = True
else: