]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35766 follow-up: Add an error check to new_type_comment() (#11766)
authorGuido van Rossum <guido@python.org>
Mon, 11 Feb 2019 16:10:42 +0000 (08:10 -0800)
committerGitHub <noreply@github.com>
Mon, 11 Feb 2019 16:10:42 +0000 (08:10 -0800)
If PyUnicode_DecodeUTF8() returns NULL, PyArena_AddPyObject() would crash.
Found by @msullivan for https://github.com/python/typed_ast/pull/93.

Python/ast.c

index 76588c345f27ca23515acbd627deba4ca72951e2..5cef3fdadc9ae97e7a22906003ad5dc47cb150cb 100644 (file)
@@ -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;