Kaydet (Commit) 00f09b38 authored tarafından Guido van Rossum's avatar Guido van Rossum

Security patch for Unix by Chris McDonough.

This uses the same precautions when trying to find a temporary
directory as when the actual tempfile is created (using O_CREAT and
O_EXCL).  On non-posix platforms, nothing is changed.
üst bfbf1138
...@@ -42,13 +42,27 @@ def gettempdir(): ...@@ -42,13 +42,27 @@ def gettempdir():
testfile = gettempprefix() + 'test' testfile = gettempprefix() + 'test'
for dir in attempdirs: for dir in attempdirs:
try: try:
filename = os.path.join(dir, testfile) filename = os.path.join(dir, testfile)
fp = open(filename, 'w') if os.name == 'posix':
fp.write('blat') try:
fp.close() fd = os.open(filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700)
os.unlink(filename) except OSError:
tempdir = dir pass
break else:
fp = os.fdopen(fd, 'w')
fp.write('blat')
fp.close()
os.unlink(filename)
del fp, fd
tempdir = dir
break
else:
fp = open(filename, 'w')
fp.write('blat')
fp.close()
os.unlink(filename)
tempdir = dir
break
except IOError: except IOError:
pass pass
if tempdir is None: if tempdir is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment