From 4ed859bc1fb9befb7af5a3309c27014b0a9a5cff Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Fri, 3 Sep 2021 16:48:11 +0100 Subject: [PATCH 1/2] bpo-1514420: Do not attempt to open files with names in <>s when formatting an exception --- Python/traceback.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Python/traceback.c b/Python/traceback.c index cdabd2900acf49..76280a35e3a5f0 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -396,6 +396,15 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent, i if (filename == NULL) return 0; + /* Do not attempt to open things like or */ + assert(PyUnicode_Check(filename)); + if (PyUnicode_READ_CHAR(filename, 0) == '<') { + Py_ssize_t len = PyUnicode_GET_LENGTH(filename); + if (len > 0 && PyUnicode_READ_CHAR(filename, len - 1) == '>') { + return 0; + } + } + io = PyImport_ImportModuleNoBlock("io"); if (io == NULL) return -1; From b1161b5efbdb32b8cda3eba9a2b4b4f6ff197ffa Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 3 Sep 2021 16:18:11 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2021-09-03-16-18-10.bpo-1514420.2Lumpj.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-09-03-16-18-10.bpo-1514420.2Lumpj.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-09-03-16-18-10.bpo-1514420.2Lumpj.rst b/Misc/NEWS.d/next/Core and Builtins/2021-09-03-16-18-10.bpo-1514420.2Lumpj.rst new file mode 100644 index 00000000000000..fdd5cd70c5c2fb --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-09-03-16-18-10.bpo-1514420.2Lumpj.rst @@ -0,0 +1 @@ +Interpreter no longer attempts to open files with names in angle brackets (like "" or "") when formatting an exception. \ No newline at end of file