summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Python/flowgraph.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/tools/python3/Python/flowgraph.c')
-rw-r--r--contrib/tools/python3/Python/flowgraph.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/contrib/tools/python3/Python/flowgraph.c b/contrib/tools/python3/Python/flowgraph.c
index ecf510842ea..baba1f75b9c 100644
--- a/contrib/tools/python3/Python/flowgraph.c
+++ b/contrib/tools/python3/Python/flowgraph.c
@@ -1244,6 +1244,14 @@ get_const_value(int opcode, int oparg, PyObject *co_consts)
PyObject *constant = NULL;
assert(OPCODE_HAS_CONST(opcode));
if (opcode == LOAD_CONST) {
+ assert(PyList_Check(co_consts));
+ Py_ssize_t n = PyList_GET_SIZE(co_consts);
+ if (oparg < 0 || oparg >= n) {
+ PyErr_Format(PyExc_ValueError,
+ "LOAD_CONST index %d is out of range for consts (len=%zd)",
+ oparg, n);
+ return NULL;
+ }
constant = PyList_GET_ITEM(co_consts, oparg);
}
@@ -2032,6 +2040,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
if (index_map == NULL) {
+ PyErr_NoMemory();
goto end;
}
for (Py_ssize_t i = 1; i < nconsts; i++) {
@@ -2045,6 +2054,12 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
for (int i = 0; i < b->b_iused; i++) {
if (OPCODE_HAS_CONST(b->b_instr[i].i_opcode)) {
int index = b->b_instr[i].i_oparg;
+ if (index < 0 || index >= nconsts) {
+ PyErr_Format(PyExc_ValueError,
+ "LOAD_CONST index %d is out of range for consts (len=%zd)",
+ index, nconsts);
+ goto end;
+ }
index_map[index] = index;
}
}
@@ -2083,6 +2098,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
/* adjust const indices in the bytecode */
reverse_index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
if (reverse_index_map == NULL) {
+ PyErr_NoMemory();
goto end;
}
for (Py_ssize_t i = 0; i < nconsts; i++) {