Skip to content

Commit b7f1b38

Browse files
committed
Issue python#18552: Check return value of PyArena_AddPyObject() in obj2ast_object().
2 parents b318990 + 70c94e7 commit b7f1b38

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #18552: Check return value of PyArena_AddPyObject() in
14+
obj2ast_object().
15+
1316
- Issue #18560: Fix potential NULL pointer dereference in sum().
1417

1518
- Issue #18520: Add a new PyStructSequence_InitType2() function, same than

Parser/asdl_c.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,13 @@ def visitModule(self, mod):
862862
{
863863
if (obj == Py_None)
864864
obj = NULL;
865-
if (obj)
866-
PyArena_AddPyObject(arena, obj);
867-
Py_XINCREF(obj);
865+
if (obj) {
866+
if (PyArena_AddPyObject(arena, obj) < 0) {
867+
*out = NULL;
868+
return -1;
869+
}
870+
Py_INCREF(obj);
871+
}
868872
*out = obj;
869873
return 0;
870874
}

Python/Python-ast.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,13 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
704704
{
705705
if (obj == Py_None)
706706
obj = NULL;
707-
if (obj)
708-
PyArena_AddPyObject(arena, obj);
709-
Py_XINCREF(obj);
707+
if (obj) {
708+
if (PyArena_AddPyObject(arena, obj) < 0) {
709+
*out = NULL;
710+
return -1;
711+
}
712+
Py_INCREF(obj);
713+
}
710714
*out = obj;
711715
return 0;
712716
}

0 commit comments

Comments
 (0)