diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-06 11:03:01 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-07-06 11:03:01 (GMT) |
commit | 02eae6b1f23d1c5ea87816f1f8d15cdab2dfaf0a (patch) | |
tree | fbce883b7dda0006f6124e94ef8af88f26c9ee26 /Modules/_sre.c | |
parent | e12aa62d689f435b9b75cde51e432d997646d5f9 (diff) | |
parent | 03d6ee382340dc1db57d7bbc269de0e102ed1a7a (diff) | |
download | cpython-02eae6b1f23d1c5ea87816f1f8d15cdab2dfaf0a.zip cpython-02eae6b1f23d1c5ea87816f1f8d15cdab2dfaf0a.tar.gz cpython-02eae6b1f23d1c5ea87816f1f8d15cdab2dfaf0a.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.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index 4f47393..957ccbc 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -994,7 +994,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); @@ -1191,6 +1191,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 @@ -2564,6 +2566,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; @@ -2575,10 +2580,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; } @@ -2597,6 +2606,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; @@ -2608,10 +2620,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; } |