summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-02-04 20:55:40 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-02-04 20:55:40 (GMT)
commit86e42376c2f41e6601b1844fb127f2f2e7b5349a (patch)
treec0f806005f196f632922d5f2ea4d3d813c4e26a9 /Modules/_sre.c
parent75c0d4f6bb97e723adc3a03c0ff6aaaee0c6981a (diff)
parent7e10dbbd45503268f7bb3b241e30745df6c91b99 (diff)
downloadcpython-86e42376c2f41e6601b1844fb127f2f2e7b5349a.zip
cpython-86e42376c2f41e6601b1844fb127f2f2e7b5349a.tar.gz
cpython-86e42376c2f41e6601b1844fb127f2f2e7b5349a.tar.bz2
Issue #29444: Fixed out-of-bounds buffer access in the group() method of
the match object. Based on patch by WGH.
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 979e61f..d092496 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -2003,6 +2003,7 @@ match_getslice_by_index(MatchObject* self, Py_ssize_t index, PyObject* def)
Py_buffer view;
PyObject *result;
void* ptr;
+ Py_ssize_t i, j;
if (index < 0 || index >= self->groups) {
/* raise IndexError if we were given a bad group number */
@@ -2024,8 +2025,12 @@ match_getslice_by_index(MatchObject* self, Py_ssize_t index, PyObject* def)
ptr = getstring(self->string, &length, &isbytes, &charsize, &view);
if (ptr == NULL)
return NULL;
- result = getslice(isbytes, ptr,
- self->string, self->mark[index], self->mark[index+1]);
+
+ i = self->mark[index];
+ j = self->mark[index+1];
+ i = Py_MIN(i, length);
+ j = Py_MIN(j, length);
+ result = getslice(isbytes, ptr, self->string, i, j);
if (isbytes && view.buf != NULL)
PyBuffer_Release(&view);
return result;