mirror of
https://github.com/python/cpython
synced 2024-09-16 03:29:57 +00:00
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>
This commit is contained in:
parent
4d2957c1b9
commit
f71300cb04
|
@ -0,0 +1 @@
|
|||
Interpreter no longer attempts to open files with names in angle brackets (like "<string>" or "<stdin>") when formatting an exception.
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue