Issue #18684: Fixed reading out of the buffer in the re module.

This commit is contained in:
Serhiy Storchaka 2015-07-06 13:58:33 +03:00
parent 0357268d96
commit 03d6ee3823
3 changed files with 43 additions and 14 deletions

View file

@ -883,7 +883,7 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
}
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);
@ -1081,6 +1081,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
@ -2567,6 +2569,9 @@ scanner_match(ScannerObject* self, PyObject *unused)
PyObject* match;
Py_ssize_t status;
if (state->start == NULL)
Py_RETURN_NONE;
state_reset(state);
state->ptr = state->start;
@ -2578,10 +2583,14 @@ scanner_match(ScannerObject* self, PyObject *unused)
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 @@ scanner_search(ScannerObject* self, PyObject *unused)
PyObject* match;
Py_ssize_t status;
if (state->start == NULL)
Py_RETURN_NONE;
state_reset(state);
state->ptr = state->start;
@ -2605,10 +2617,14 @@ scanner_search(ScannerObject* self, PyObject *unused)
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;
}