diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-09-20 15:10:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-20 15:10:30 (GMT) |
commit | f71300cb0442f16ee9abc938e12537aec1eb5979 (patch) | |
tree | 05c61c5e07dc6dba65c9fff88b851b8d73fbfc74 /Python | |
parent | 4d2957c1b9a915f76da418e89bf9b5add141ca3e (diff) | |
download | cpython-f71300cb0442f16ee9abc938e12537aec1eb5979.zip cpython-f71300cb0442f16ee9abc938e12537aec1eb5979.tar.gz cpython-f71300cb0442f16ee9abc938e12537aec1eb5979.tar.bz2 |
bpo-1514420: Do not attempt to open files with names in <>s when formatting an exception (GH-28143)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/traceback.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/traceback.c b/Python/traceback.c index cdabd29..76280a3 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 <string> or <stdin> */ + 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; |