summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2016-06-24 19:03:43 (GMT)
committerBrett Cannon <brett@python.org>2016-06-24 19:03:43 (GMT)
commitc78ca1e044b7ca4c1764bb3670196e72351d4467 (patch)
tree3435d7babe85991192e645d12c9ec2b24b4de04f /Modules
parent19b2a53a82c8f4d179efdc39fb39f766191cac2b (diff)
downloadcpython-c78ca1e044b7ca4c1764bb3670196e72351d4467.zip
cpython-c78ca1e044b7ca4c1764bb3670196e72351d4467.tar.gz
cpython-c78ca1e044b7ca4c1764bb3670196e72351d4467.tar.bz2
Issue #27186: Update os.fspath()/PyOS_FSPath() to check the return
type of __fspath__(). As part of this change, also make sure that the pure Python implementation of os.fspath() is tested.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 7d82490..df802cb 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -12317,12 +12317,21 @@ PyOS_FSPath(PyObject *path)
if (NULL == func) {
return PyErr_Format(PyExc_TypeError,
"expected str, bytes or os.PathLike object, "
- "not %S",
- path->ob_type);
+ "not %.200s",
+ Py_TYPE(path)->tp_name);
}
path_repr = PyObject_CallFunctionObjArgs(func, NULL);
Py_DECREF(func);
+ if (!(PyUnicode_Check(path_repr) || PyBytes_Check(path_repr))) {
+ PyErr_Format(PyExc_TypeError,
+ "expected %.200s.__fspath__() to return str or bytes, "
+ "not %.200s", Py_TYPE(path)->tp_name,
+ Py_TYPE(path_repr)->tp_name);
+ Py_DECREF(path_repr);
+ return NULL;
+ }
+
return path_repr;
}