From 2bea7716093012319b5e6a4260fe802b15031f21 Mon Sep 17 00:00:00 2001 From: Xtreak Date: Thu, 26 Jul 2018 21:50:34 +0530 Subject: bpo-34229: Check start and stop of slice object to be long when they are not int in PySlice_GetIndices (GH-8480) --- Modules/_testcapimodule.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Modules') diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index f57176d632..67488e70e4 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1559,6 +1559,29 @@ getargs_et_hash(PyObject *self, PyObject *args) return result; } +static PyObject * +get_indices(PyObject *self, PyObject *args) +{ + int result; + PySliceObject *slice; + Py_ssize_t length, start, stop, step; + + if (!PyArg_ParseTuple(args, "On", &slice, &length)) + return NULL; + + result = PySlice_GetIndices(slice, length, &start, &stop, &step); + + if (PyErr_Occurred()) { + assert(result == -1); + return NULL; + } + + if (result == -1) { + Py_RETURN_NONE; + } + return Py_BuildValue("innn", result, start, stop, step); +} + static PyObject * parse_tuple_and_keywords(PyObject *self, PyObject *args) { @@ -2664,6 +2687,7 @@ static PyMethodDef TestMethods[] = { #ifdef Py_USING_UNICODE {"test_empty_argparse", (PyCFunction)test_empty_argparse,METH_NOARGS}, #endif + {"get_indices", get_indices, METH_VARARGS}, {"parse_tuple_and_keywords", parse_tuple_and_keywords, METH_VARARGS}, {"test_null_strings", (PyCFunction)test_null_strings, METH_NOARGS}, {"test_string_from_format", (PyCFunction)test_string_from_format, METH_NOARGS}, -- cgit v1.2.1