aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-08-06 18:55:26 +0000
committerMark Dickinson <dickinsm@gmail.com>2010-08-06 18:55:26 +0000
commite6fc7401a92c7b51a80782d8095819b9909a0322 (patch)
treed31c18c8224c1a8248091b54c156ff45726212a7 /Objects/sliceobject.c
parentIssue #3210: Ensure stdio handles are closed if CreateProcess fails (diff)
downloadcpython-e6fc7401a92c7b51a80782d8095819b9909a0322.tar.gz
cpython-e6fc7401a92c7b51a80782d8095819b9909a0322.tar.bz2
cpython-e6fc7401a92c7b51a80782d8095819b9909a0322.zip
In PySlice_IndicesEx, clip the step to [-PY_SSIZE_T_MAX, PY_SSIZE_T_MAX] rather than [PY_SSIZE_T_MIN, PY_SSIZE_T_MAX].
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index ee89006688d..55fda52987f 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -131,7 +131,8 @@ PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
int
PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
- Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength)
+ Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
+ Py_ssize_t *slicelength)
{
/* this is harder to get right than you might think */
@@ -147,6 +148,13 @@ PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
"slice step cannot be zero");
return -1;
}
+ /* Here *step might be -PY_SSIZE_T_MAX-1; in this case we replace it
+ * with -PY_SSIZE_T_MAX. This doesn't affect the semantics, and it
+ * guards against later undefined behaviour resulting from code that
+ * does "step = -step" as part of a slice reversal.
+ */
+ if (*step < -PY_SSIZE_T_MAX)
+ *step = -PY_SSIZE_T_MAX;
}
defstart = *step < 0 ? length-1 : 0;