1. mirror
  2. cpython


Éric Araujo  committed 4a2814f

Create ~/.pypirc securely (#13512).

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.

  • Participants
  • Parent commits d978828
  • Branches 3.2

Comments (0)

Files changed (3)

File Lib/distutils/config.py

View file
  • Ignore whitespace
 that uses .pypirc in the distutils.command package.
 import os
-import sys
 from configparser import ConfigParser
 from distutils.cmd import Command
     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."""

File Misc/ACKS

View file
  • Ignore whitespace
 Drew Jenkins
 Flemming Kjær Jensen
 Philip H. Jensen
+Philip Jenvey
 MunSic Jeong
 Chris Jerdonek
 Pedro Diaz Jimenez

File Misc/NEWS

View file
  • Ignore whitespace
 - 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.