From f71300cb0442f16ee9abc938e12537aec1eb5979 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Mon, 20 Sep 2021 16:10:30 +0100 Subject: bpo-1514420: Do not attempt to open files with names in <>s when formatting an exception (GH-28143) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Ɓukasz Langa --- Python/traceback.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Python/traceback.c') diff --git a/Python/traceback.c b/Python/traceback.c index cdabd2900a..76280a35e3 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; -- cgit v1.2.1