summaryrefslogtreecommitdiff
path: root/Python/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index b458f7319a..6e68d0fd5d 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -677,6 +677,14 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
goto exitUnchanged;
codestr = memcpy(codestr, PyString_AS_STRING(code), codelen);
+ /* Verify that RETURN_VALUE terminates the codestring. This allows
+ the various transformation patterns to look ahead several
+ instructions without additional checks to make sure they are not
+ looking beyond the end of the code string.
+ */
+ if (codestr[codelen-1] != RETURN_VALUE)
+ goto exitUnchanged;
+
/* Mapping to new jump targets after NOPs are removed */
addrmap = PyMem_Malloc(codelen * sizeof(int));
if (addrmap == NULL)