Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d61926e

Browse files
author
Éric Araujo
committed
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.
1 parent 3e4a3dc commit d61926e

3 files changed

Lines changed: 5 additions & 10 deletions

File tree

Lib/distutils/config.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
that uses .pypirc in the distutils.command package.
55
"""
66
import os
7-
import sys
87
from configparser import ConfigParser
98

109
from distutils.cmd import Command
@@ -43,16 +42,8 @@ def _get_rc_file(self):
4342
def _store_pypirc(self, username, password):
4443
"""Creates a default .pypirc file."""
4544
rc = self._get_rc_file()
46-
f = open(rc, 'w')
47-
try:
45+
with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
4846
f.write(DEFAULT_PYPIRC % (username, password))
49-
finally:
50-
f.close()
51-
try:
52-
os.chmod(rc, 0o600)
53-
except OSError:
54-
# should do something better here
55-
pass
5647

5748
def _read_pypirc(self):
5849
"""Reads the .pypirc file."""

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ Zbyszek Jędrzejewski-Szmek
512512
Drew Jenkins
513513
Flemming Kjær Jensen
514514
Philip H. Jensen
515+
Philip Jenvey
515516
MunSic Jeong
516517
Chris Jerdonek
517518
Pedro Diaz Jimenez

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ Library
177177

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

180+
- Issue #13512: Create ~/.pypirc securely (CVE-2011-4944). Initial patch by
181+
Philip Jenvey, tested by Mageia and Debian.
182+
180183
- Issue #7719: Make distutils ignore ``.nfs*`` files instead of choking later
181184
on. Initial patch by SilentGhost and Jeff Ramnani.
182185

0 commit comments

Comments
 (0)