diff options
author | Xtreak <tirkarthi@users.noreply.github.com> | 2018-07-26 21:50:34 +0530 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2018-07-26 19:20:34 +0300 |
commit | 2bea7716093012319b5e6a4260fe802b15031f21 (patch) | |
tree | dabb99b7e01742747c20f9ed5bdcf1a8aaed3ab5 /Modules | |
parent | 1c8f6553ad5a7f97495972da8f35f4dabcb372d4 (diff) | |
download | cpython-git-2bea7716093012319b5e6a4260fe802b15031f21.tar.gz |
bpo-34229: Check start and stop of slice object to be long when they are not int in PySlice_GetIndices (GH-8480)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index f57176d632..67488e70e4 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1560,6 +1560,29 @@ getargs_et_hash(PyObject *self, PyObject *args) } 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) { PyObject *sub_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}, |