Issue #27512: Don't segfault when os.fspath() calls an object whose

__fspath__() raises an exception.

Thanks to Xiang Zhang for the patch.
This commit is contained in:
Brett Cannon 2016-07-15 10:41:49 -07:00
parent 1e6755ba43
commit 044283a426
3 changed files with 23 additions and 6 deletions

View file

@ -12319,6 +12319,10 @@ PyOS_FSPath(PyObject *path)
path_repr = PyObject_CallFunctionObjArgs(func, NULL);
Py_DECREF(func);
if (NULL == path_repr) {
return NULL;
}
if (!(PyUnicode_Check(path_repr) || PyBytes_Check(path_repr))) {
PyErr_Format(PyExc_TypeError,
"expected %.200s.__fspath__() to return str or bytes, "