mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +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
2 changed files with 10 additions and 0 deletions
|
@ -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)
|
if (filename == NULL)
|
||||||
return 0;
|
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");
|
io = PyImport_ImportModuleNoBlock("io");
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue