bpo-31577: Fix a crash in os.utime() in case of a bad ns argument. (GH-3752)

This commit is contained in:
Oren Milman 2018-09-12 22:14:35 +03:00 • committed by Serhiy Storchaka
parent e502451781
commit 0bd1a2dcfd
3 changed files with 24 additions and 0 deletions

View file

@ -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;