From: Guido van Rossum Date: Mon, 11 Feb 2019 16:10:42 +0000 (-0800) Subject: bpo-35766 follow-up: Add an error check to new_type_comment() (#11766) X-Git-Tag: v3.8.0a2~92 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4b250fc1da9c893803cf724a4974450b5e10bd8a;p=thirdparty%2FPython%2Fcpython.git bpo-35766 follow-up: Add an error check to new_type_comment() (#11766) If PyUnicode_DecodeUTF8() returns NULL, PyArena_AddPyObject() would crash. Found by @msullivan for https://github.com/python/typed_ast/pull/93. --- diff --git a/Python/ast.c b/Python/ast.c index 76588c345f27..5cef3fdadc9a 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -702,6 +702,8 @@ static string new_type_comment(const char *s, struct compiling *c) { PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL); + if (res == NULL) + return NULL; if (PyArena_AddPyObject(c->c_arena, res) < 0) { Py_DECREF(res); return NULL;