Skip to content

Commit 70c94e7

Browse files
committed
Issue python#18552: Check return value of PyArena_AddPyObject() in obj2ast_object().
1 parent 1acc129 commit 70c94e7

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
@@ -12,6 +12,9 @@ What's New in Python 3.3.3 release candidate 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #18552: Check return value of PyArena_AddPyObject() in
16+
obj2ast_object().
17+
1518
- Issue #18560: Fix potential NULL pointer dereference in sum().
1619

1720
- Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],

‎Parser/asdl_c.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,9 +834,13 @@ def visitModule(self, mod):
834834
{
835835
if (obj == Py_None)
836836
obj = NULL;
837-
if (obj)
838-
PyArena_AddPyObject(arena, obj);
839-
Py_XINCREF(obj);
837+
if (obj) {
838+
if (PyArena_AddPyObject(arena, obj) < 0) {
839+
*out = NULL;
840+
return -1;
841+
}
842+
Py_INCREF(obj);
843+
}
840844
*out = obj;
841845
return 0;
842846
}

‎Python/Python-ast.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,13 @@ static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
688688
{
689689
if (obj == Py_None)
690690
obj = NULL;
691-
if (obj)
692-
PyArena_AddPyObject(arena, obj);
693-
Py_XINCREF(obj);
691+
if (obj) {
692+
if (PyArena_AddPyObject(arena, obj) < 0) {
693+
*out = NULL;
694+
return -1;
695+
}
696+
Py_INCREF(obj);
697+
}
694698
*out = obj;
695699
return 0;
696700
}

0 commit comments

Comments
 (0)