aboutsummaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2021-09-20 16:10:30 +0100
committerGitHub <noreply@github.com>2021-09-20 17:10:30 +0200
commitf71300cb0442f16ee9abc938e12537aec1eb5979 (patch)
tree05c61c5e07dc6dba65c9fff88b851b8d73fbfc74 /Python
parent4d2957c1b9a915f76da418e89bf9b5add141ca3e (diff)
downloadcpython3-f71300cb0442f16ee9abc938e12537aec1eb5979.tar.gz
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.c9
1 files changed, 9 insertions, 0 deletions
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 <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;