bpo-10496: distutils check_environ() handles getpwuid() error (GH-10931) · python/cpython@17d0c05 · GitHub
Skip to content

Commit 17d0c05

Browse files
authored
bpo-10496: distutils check_environ() handles getpwuid() error (GH-10931)
check_environ() of distutils.utils now catchs KeyError on calling pwd.getpwuid(): don't create the HOME environment variable in this case.
1 parent e6b247c commit 17d0c05

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

Lib/distutils/tests/test_util.py

Lines changed: 25 additions & 9 deletions

Lib/distutils/util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,13 @@ def check_environ ():
157157
return
158158

159159
if os.name == 'posix' and 'HOME' not in os.environ:
160-
import pwd
161-
os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
160+
try:
161+
import pwd
162+
os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
163+
except (ImportError, KeyError):
164+
# bpo-10496: if the current user identifier doesn't exist in the
165+
# password database, do nothing
166+
pass
162167

163168
if 'PLAT' not in os.environ:
164169
os.environ['PLAT'] = get_platform()
Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)