diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-08-29 05:57:05 -0700 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2021-08-30 23:54:29 +0200 |
commit | 8a6f141b997b6b706827b9f113cc2863f1aac43e (patch) | |
tree | ceda503726a9cd9e12f3956254eb020b0be60fe9 | |
parent | [3.7] bpo-43124: Fix smtplib multiple CRLF injection (GH-25987) (GH-28037) (diff) | |
download | cpython-8a6f141b997b6b706827b9f113cc2863f1aac43e.tar.gz cpython-8a6f141b997b6b706827b9f113cc2863f1aac43e.tar.bz2 cpython-8a6f141b997b6b706827b9f113cc2863f1aac43e.zip |
bpo-42278: Use tempfile.TemporaryDirectory rather than tempfile.mktemp in pydoc (GH-23200) (GH-28026)gentoo-3.7.11_p1
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit c9227df5a9d8e958a2324cf0deba8524d1ded26a)
Co-authored-by: E-Paine <63801254+E-Paine@users.noreply.github.com>
-rw-r--r-- | Lib/pydoc.py | 13 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Security/2021-08-29-12-39-44.bpo-42278.jvmQz_.rst | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 9677c0d0468..f03678be74b 100644 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -1511,13 +1511,14 @@ def pipepager(text, cmd): def tempfilepager(text, cmd): """Page through text by invoking a program on a temporary file.""" import tempfile - filename = tempfile.mktemp() - with open(filename, 'w', errors='backslashreplace') as file: - file.write(text) - try: + with tempfile.TemporaryDirectory() as tempdir: + filename = os.path.join(tempdir, 'pydoc.out') + with open(filename, 'w', errors='backslashreplace', + encoding=os.device_encoding(0) if + sys.platform == 'win32' else None + ) as file: + file.write(text) os.system(cmd + ' "' + filename + '"') - finally: - os.unlink(filename) def _escape_stdout(text): # Escape non-encodable characters to avoid encoding errors later diff --git a/Misc/NEWS.d/next/Security/2021-08-29-12-39-44.bpo-42278.jvmQz_.rst b/Misc/NEWS.d/next/Security/2021-08-29-12-39-44.bpo-42278.jvmQz_.rst new file mode 100644 index 00000000000..db880cd9026 --- /dev/null +++ b/Misc/NEWS.d/next/Security/2021-08-29-12-39-44.bpo-42278.jvmQz_.rst @@ -0,0 +1,2 @@ +Replaced usage of :func:`tempfile.mktemp` with +:class:`~tempfile.TemporaryDirectory` to avoid a potential race condition. |