summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2018-09-12 19:14:35 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-09-12 19:14:35 (GMT)
commit0bd1a2dcfdf36b181385ae61361e7692f4ebb0fd (patch)
tree0adf66fd5134076264070c7cd2777eb310d38ae3 /Modules/posixmodule.c
parente5024517811ee990b770fca0ba7058742d00e032 (diff)
downloadcpython-0bd1a2dcfdf36b181385ae61361e7692f4ebb0fd.zip
cpython-0bd1a2dcfdf36b181385ae61361e7692f4ebb0fd.tar.gz
cpython-0bd1a2dcfdf36b181385ae61361e7692f4ebb0fd.tar.bz2
bpo-31577: Fix a crash in os.utime() in case of a bad ns argument. (GH-3752)
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 48bd5dc..7c02351 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4630,6 +4630,12 @@ split_py_long_to_s_and_ns(PyObject *py_long, time_t *s, long *ns)
divmod = PyNumber_Divmod(py_long, billion);
if (!divmod)
goto exit;
+ if (!PyTuple_Check(divmod) || PyTuple_GET_SIZE(divmod) != 2) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s.__divmod__() must return a 2-tuple, not %.200s",
+ Py_TYPE(py_long)->tp_name, Py_TYPE(divmod)->tp_name);
+ goto exit;
+ }
*s = _PyLong_AsTime_t(PyTuple_GET_ITEM(divmod, 0));
if ((*s == -1) && PyErr_Occurred())
goto exit;