mirror of https://github.com/python/cpython
[Backport to 2-5maint of r52147 | andrew.kuchling ; the buildbots seem OK
with this change.] Cause a PyObject_Malloc() failure to trigger a MemoryError, and then add 'if (PyErr_Occurred())' checks to various places so that NULL is returned properly.
This commit is contained in:
parent
4b63c21d6f
commit
d79524a4cc
|
@ -49,6 +49,7 @@ Extension Modules
|
||||||
|
|
||||||
- Fix itertools.count(n) to work with negative numbers again.
|
- Fix itertools.count(n) to work with negative numbers again.
|
||||||
|
|
||||||
|
- Make regex engine raise MemoryError if allocating memory fails.
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -1166,9 +1166,10 @@ entrance:
|
||||||
|
|
||||||
/* install new repeat context */
|
/* install new repeat context */
|
||||||
ctx->u.rep = (SRE_REPEAT*) PyObject_MALLOC(sizeof(*ctx->u.rep));
|
ctx->u.rep = (SRE_REPEAT*) PyObject_MALLOC(sizeof(*ctx->u.rep));
|
||||||
/* XXX(nnorwitz): anything else we need to do on error? */
|
if (!ctx->u.rep) {
|
||||||
if (!ctx->u.rep)
|
PyErr_NoMemory();
|
||||||
RETURN_FAILURE;
|
RETURN_FAILURE;
|
||||||
|
}
|
||||||
ctx->u.rep->count = -1;
|
ctx->u.rep->count = -1;
|
||||||
ctx->u.rep->pattern = ctx->pattern;
|
ctx->u.rep->pattern = ctx->pattern;
|
||||||
ctx->u.rep->prev = state->repeat;
|
ctx->u.rep->prev = state->repeat;
|
||||||
|
@ -1884,6 +1885,8 @@ pattern_match(PatternObject* self, PyObject* args, PyObject* kw)
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE(("|%p|%p|END\n", PatternObject_GetCode(self), state.ptr));
|
TRACE(("|%p|%p|END\n", PatternObject_GetCode(self), state.ptr));
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
state_fini(&state);
|
state_fini(&state);
|
||||||
|
|
||||||
|
@ -1922,6 +1925,9 @@ pattern_search(PatternObject* self, PyObject* args, PyObject* kw)
|
||||||
|
|
||||||
state_fini(&state);
|
state_fini(&state);
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return pattern_new_match(self, &state, status);
|
return pattern_new_match(self, &state, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2071,6 +2077,9 @@ pattern_findall(PatternObject* self, PyObject* args, PyObject* kw)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (status <= 0) {
|
if (status <= 0) {
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -2198,6 +2207,9 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (status <= 0) {
|
if (status <= 0) {
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -2347,6 +2359,9 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (status <= 0) {
|
if (status <= 0) {
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
break;
|
break;
|
||||||
|
@ -3250,6 +3265,8 @@ scanner_match(ScannerObject* self, PyObject *unused)
|
||||||
status = sre_umatch(state, PatternObject_GetCode(self->pattern));
|
status = sre_umatch(state, PatternObject_GetCode(self->pattern));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
match = pattern_new_match((PatternObject*) self->pattern,
|
match = pattern_new_match((PatternObject*) self->pattern,
|
||||||
state, status);
|
state, status);
|
||||||
|
@ -3281,6 +3298,8 @@ scanner_search(ScannerObject* self, PyObject *unused)
|
||||||
status = sre_usearch(state, PatternObject_GetCode(self->pattern));
|
status = sre_usearch(state, PatternObject_GetCode(self->pattern));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
match = pattern_new_match((PatternObject*) self->pattern,
|
match = pattern_new_match((PatternObject*) self->pattern,
|
||||||
state, status);
|
state, status);
|
||||||
|
|
Loading…
Reference in New Issue