diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-10-10 19:23:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-10 19:23:42 (GMT) |
commit | 98c4433a81a4cd88c7438adbee1f2aa486188ca3 (patch) | |
tree | 68dd030d113eb842692d4f50475992a110fb7154 /Python | |
parent | 02a1603f918b9862e164e4fd050c505b16bc9f57 (diff) | |
download | cpython-98c4433a81a4cd88c7438adbee1f2aa486188ca3.zip cpython-98c4433a81a4cd88c7438adbee1f2aa486188ca3.tar.gz cpython-98c4433a81a4cd88c7438adbee1f2aa486188ca3.tar.bz2 |
bpo-41991: Remove _PyObject_HasAttrId (GH-22629)
It can silence arbitrary exceptions.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/errors.c | 19 | ||||
-rw-r--r-- | Python/pythonrun.c | 6 |
2 files changed, 21 insertions, 4 deletions
diff --git a/Python/errors.c b/Python/errors.c index 720f18b..02cf479 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1593,9 +1593,18 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) } Py_DECREF(tmp); } + else { + _PyErr_Clear(tstate); + } } if (exc != PyExc_SyntaxError) { - if (!_PyObject_HasAttrId(v, &PyId_msg)) { + if (_PyObject_LookupAttrId(v, &PyId_msg, &tmp) < 0) { + _PyErr_Clear(tstate); + } + else if (tmp) { + Py_DECREF(tmp); + } + else { tmp = PyObject_Str(v); if (tmp) { if (_PyObject_SetAttrId(v, &PyId_msg, tmp)) { @@ -1607,7 +1616,13 @@ PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) _PyErr_Clear(tstate); } } - if (!_PyObject_HasAttrId(v, &PyId_print_file_and_line)) { + if (_PyObject_LookupAttrId(v, &PyId_print_file_and_line, &tmp) < 0) { + _PyErr_Clear(tstate); + } + else if (tmp) { + Py_DECREF(tmp); + } + else { if (_PyObject_SetAttrId(v, &PyId_print_file_and_line, Py_None)) { _PyErr_Clear(tstate); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ff80103..a45ca3b 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -770,7 +770,7 @@ static void print_exception(PyObject *f, PyObject *value) { int err = 0; - PyObject *type, *tb; + PyObject *type, *tb, *tmp; _Py_IDENTIFIER(print_file_and_line); if (!PyExceptionInstance_Check(value)) { @@ -789,10 +789,12 @@ print_exception(PyObject *f, PyObject *value) if (tb && tb != Py_None) err = PyTraceBack_Print(tb, f); if (err == 0 && - _PyObject_HasAttrId(value, &PyId_print_file_and_line)) + (err = _PyObject_LookupAttrId(value, &PyId_print_file_and_line, &tmp)) > 0) { PyObject *message, *filename, *text; Py_ssize_t lineno, offset; + err = 0; + Py_DECREF(tmp); if (!parse_syntax_error(value, &message, &filename, &lineno, &offset, &text)) PyErr_Clear(); |