Skip to content

Commit

Permalink
Create ~/.pypirc securely (python#13512).
Browse files Browse the repository at this point in the history
There was a window between the write and the chmod where the user’s
password would be exposed, depending on default permissions.  Philip
Jenvey’s patch fixes it.
  • Loading branch information
merwok committed Dec 8, 2012
1 parent 3e4a3dc commit d61926e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
11 changes: 1 addition & 10 deletions Lib/distutils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
that uses .pypirc in the distutils.command package.
"""
import os
import sys
from configparser import ConfigParser

from distutils.cmd import Command
Expand Down Expand Up @@ -43,16 +42,8 @@ def _get_rc_file(self):
def _store_pypirc(self, username, password):
"""Creates a default .pypirc file."""
rc = self._get_rc_file()
f = open(rc, 'w')
try:
with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
f.write(DEFAULT_PYPIRC % (username, password))
finally:
f.close()
try:
os.chmod(rc, 0o600)
except OSError:
# should do something better here
pass

def _read_pypirc(self):
"""Reads the .pypirc file."""
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ Zbyszek Jędrzejewski-Szmek
Drew Jenkins
Flemming Kjær Jensen
Philip H. Jensen
Philip Jenvey
MunSic Jeong
Chris Jerdonek
Pedro Diaz Jimenez
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ Library

- Issue #16628: Fix a memory leak in ctypes.resize().

- Issue #13512: Create ~/.pypirc securely (CVE-2011-4944). Initial patch by
Philip Jenvey, tested by Mageia and Debian.

- Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later
on. Initial patch by SilentGhost and Jeff Ramnani.

Expand Down

0 comments on commit d61926e

Please sign in to comment.