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.
This commit is contained in:
Guido van Rossum 2019-02-11 08:10:42 -08:00 committed by GitHub
parent 537b6caa56
commit 4b250fc1da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View 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;