summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-07-06 11:23:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-07-06 11:23:04 (GMT)
commit5bccb29de5f59ef4c7987cea9fe1589f1abedfb5 (patch)
tree83d9d1b911f478f4e55ebd533cfd8fdfb31e508f /Modules/_sre.c
parent7afe40e40ea045b08f9baf6c8c56d642b385c973 (diff)
parent02eae6b1f23d1c5ea87816f1f8d15cdab2dfaf0a (diff)
downloadcpython-5bccb29de5f59ef4c7987cea9fe1589f1abedfb5.zip
cpython-5bccb29de5f59ef4c7987cea9fe1589f1abedfb5.tar.gz
cpython-5bccb29de5f59ef4c7987cea9fe1589f1abedfb5.tar.bz2
Issue #18684: Fixed reading out of the buffer in the re module.
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 1cc8bd8..6a3d811 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -991,7 +991,7 @@ _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
}
if (state.start == state.ptr) {
- if (last == state.end)
+ if (last == state.end || state.ptr == state.end)
break;
/* skip one character */
state.start = (void*) ((char*) state.ptr + state.charsize);
@@ -1188,6 +1188,8 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
next:
/* move on */
+ if (state.ptr == state.end)
+ break;
if (state.ptr == state.start)
state.start = (void*) ((char*) state.ptr + state.charsize);
else
@@ -2561,6 +2563,9 @@ _sre_SRE_Scanner_match_impl(ScannerObject *self)
PyObject* match;
Py_ssize_t status;
+ if (state->start == NULL)
+ Py_RETURN_NONE;
+
state_reset(state);
state->ptr = state->start;
@@ -2572,10 +2577,14 @@ _sre_SRE_Scanner_match_impl(ScannerObject *self)
match = pattern_new_match((PatternObject*) self->pattern,
state, status);
- if (status == 0 || state->ptr == state->start)
+ if (status == 0)
+ state->start = NULL;
+ else if (state->ptr != state->start)
+ state->start = state->ptr;
+ else if (state->ptr != state->end)
state->start = (void*) ((char*) state->ptr + state->charsize);
else
- state->start = state->ptr;
+ state->start = NULL;
return match;
}
@@ -2594,6 +2603,9 @@ _sre_SRE_Scanner_search_impl(ScannerObject *self)
PyObject* match;
Py_ssize_t status;
+ if (state->start == NULL)
+ Py_RETURN_NONE;
+
state_reset(state);
state->ptr = state->start;
@@ -2605,10 +2617,14 @@ _sre_SRE_Scanner_search_impl(ScannerObject *self)
match = pattern_new_match((PatternObject*) self->pattern,
state, status);
- if (status == 0 || state->ptr == state->start)
+ if (status == 0)
+ state->start = NULL;
+ else if (state->ptr != state->start)
+ state->start = state->ptr;
+ else if (state->ptr != state->end)
state->start = (void*) ((char*) state->ptr + state->charsize);
else
- state->start = state->ptr;
+ state->start = NULL;
return match;
}