]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/python: check return value of PyObject_New in all cases
authorAndrew Burgess <aburgess@redhat.com>
Wed, 20 Aug 2025 09:45:09 +0000 (10:45 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 21 Aug 2025 10:47:17 +0000 (11:47 +0100)
I spotted a few cases where the return value of PyObject_New was not
being checked against nullptr, but we were dereferencing the result.

All fixed here.  The fixed functions can now return NULL, so I checked
all the callers, and I believe there will handle a return of NULL
correctly.

Assuming calls to PyObject_New never fail, there should be no user
visible changes after this commit.

No tests here as I don't know how we'd go about causing a Python
object allocation to fail.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/python/py-block.c
gdb/python/py-record.c
gdb/python/py-unwind.c

index fa7dd19228061bd9cfa802b81801b273053e0061..66ccad7e873f3abcee9b9ea2ba479318b882840c 100644 (file)
@@ -356,6 +356,9 @@ block_to_block_object (const struct block *block, struct objfile *objfile)
     }
 
   result = PyObject_New (block_object, &block_object_type);
+  if (result == nullptr)
+    return nullptr;
+
   result->block = block;
   result->objfile = objfile;
 
index 7e7904b0d3e8c79c9017ef2a5ed28bb246231681..89c2e7745e5724c6cac78482ccacfbf557add1b5 100644 (file)
@@ -696,6 +696,9 @@ gdbpy_current_recording (PyObject *self, PyObject *args)
     Py_RETURN_NONE;
 
   ret = PyObject_New (recpy_record_object, &recpy_record_type);
+  if (ret == nullptr)
+    return nullptr;
+
   ret->thread = inferior_thread ();
   ret->method = target_record_method (ret->thread->ptid);
 
index dc078ecb5f7f9831bac5cbd947efb9e57dcc192f..43125bb67c15e304056d730dc706c9260686b14c 100644 (file)
@@ -287,6 +287,8 @@ pyuw_create_unwind_info (PyObject *pyo_pending_frame,
 
   unwind_info_object *unwind_info
     = PyObject_New (unwind_info_object, &unwind_info_object_type);
+  if (unwind_info == nullptr)
+    return nullptr;
 
   unwind_info->frame_id = frame_id;
   Py_INCREF (pyo_pending_frame);