diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-11 23:33:59 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-11 23:33:59 (GMT) |
commit | 3bd6abd1294263f88ee4c0dbff3d1dfb618ec7ab (patch) | |
tree | c1a3549501d4e57c83dc74359ab6f1e0bc27e3e6 /Modules/parsermodule.c | |
parent | 4202456cd4dfb19e04a1a08b210d99933c1e024e (diff) | |
download | cpython-3bd6abd1294263f88ee4c0dbff3d1dfb618ec7ab.zip cpython-3bd6abd1294263f88ee4c0dbff3d1dfb618ec7ab.tar.gz cpython-3bd6abd1294263f88ee4c0dbff3d1dfb618ec7ab.tar.bz2 |
Issue #18408: Fix parser.sequence2st() and parser.tuple2st(): raise MemoryError
on memory allocation failure
Instead of ignoring the memory allocation failure and create invalid objects.
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index e86fe4d..d2693e3 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -809,8 +809,13 @@ build_node_children(PyObject *tuple, node *root, int *line_num) return 0; } strn = (char *)PyObject_MALLOC(len + 1); - if (strn != NULL) - (void) memcpy(strn, temp_str, len + 1); + if (strn == NULL) { + Py_DECREF(temp); + Py_XDECREF(elem); + PyErr_NoMemory(); + return 0; + } + (void) memcpy(strn, temp_str, len + 1); Py_DECREF(temp); } else if (!ISNONTERMINAL(type)) { @@ -906,8 +911,14 @@ build_node_tree(PyObject *tuple) return NULL; } res->n_str = (char *)PyObject_MALLOC(len + 1); - if (res->n_str != NULL && temp != NULL) - (void) memcpy(res->n_str, temp, len + 1); + if (res->n_str == NULL) { + Py_DECREF(res); + Py_DECREF(encoding); + Py_DECREF(tuple); + PyErr_NoMemory(); + return NULL; + } + (void) memcpy(res->n_str, temp, len + 1); Py_DECREF(encoding); Py_DECREF(tuple); } |