summaryrefslogtreecommitdiffstats
path: root/Modules/parsermodule.c
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-12-08 23:31:48 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-12-08 23:31:48 (GMT)
commite239d23e8cc66605f548585ad4489a8f12fc070d (patch)
treee165422c11006a4f3595742dd40a7a2095ef59ce /Modules/parsermodule.c
parent1b2bd3b348d7bb861ae8c92853e5058766ebff80 (diff)
downloadcpython-e239d23e8cc66605f548585ad4489a8f12fc070d.zip
cpython-e239d23e8cc66605f548585ad4489a8f12fc070d.tar.gz
cpython-e239d23e8cc66605f548585ad4489a8f12fc070d.tar.bz2
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r--Modules/parsermodule.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 27b680f..e959321 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -792,6 +792,11 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
}
}
temp_str = _PyUnicode_AsStringAndSize(temp, &len);
+ if (temp_str == NULL) {
+ Py_DECREF(temp);
+ Py_XDECREF(elem);
+ return 0;
+ }
strn = (char *)PyObject_MALLOC(len + 1);
if (strn != NULL)
(void) memcpy(strn, temp_str, len + 1);
@@ -870,6 +875,8 @@ build_node_tree(PyObject *tuple)
encoding = PySequence_GetItem(tuple, 2);
/* tuple isn't borrowed anymore here, need to DECREF */
tuple = PySequence_GetSlice(tuple, 0, 2);
+ if (tuple == NULL)
+ return NULL;
}
res = PyNode_New(num);
if (res != NULL) {
@@ -881,6 +888,12 @@ build_node_tree(PyObject *tuple)
Py_ssize_t len;
const char *temp;
temp = _PyUnicode_AsStringAndSize(encoding, &len);
+ if (temp == NULL) {
+ Py_DECREF(res);
+ Py_DECREF(encoding);
+ Py_DECREF(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);