Mercurial > cpython-lru_cache-weakref
diff Modules/parsermodule.c @ 66799:50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
| author | Alexander Belopolsky <alexander.belopolsky@gmail.com> |
|---|---|
| date | Wed, 08 Dec 2010 23:31:48 +0000 |
| parents | 724920a015f7 |
| children | 3c9232a684ae |
line wrap: on
line diff
--- a/Modules/parsermodule.c Wed Dec 08 22:53:00 2010 +0000 +++ b/Modules/parsermodule.c Wed Dec 08 23:31:48 2010 +0000 @@ -792,6 +792,11 @@ } } 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 @@ 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 @@ 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);
