Commit 2656bc47 authored by Simon Feltman's avatar Simon Feltman
Browse files

Fix crash when setting property of type object to an incorrect type

Add type check when marshaling an object from Python for GObject types.
Add PyGObject_Type as part of the pygobject API to check for this.

https://bugzilla.gnome.org/show_bug.cgi?id=695420
parent 44587f42
......@@ -2086,7 +2086,8 @@ struct _PyGObject_Functions pygobject_api_functions = {
pyglib_option_group_new,
pyg_type_from_object_strict,
pygobject_new_full
pygobject_new_full,
&PyGObject_Type
};
/* for addon libraries ... */
......
......@@ -191,6 +191,7 @@ struct _PyGObject_Functions {
GType (* type_from_object_strict) (PyObject *obj, gboolean strict);
PyObject *(* newgobj_full)(GObject *obj, gboolean steal, gpointer g_class);
PyTypeObject *object_type;
};
#ifndef _INSIDE_PYGOBJECT_
......@@ -206,6 +207,7 @@ struct _PyGObject_Functions *_PyGObject_API;
#define pygobject_lookup_class (_PyGObject_API->lookup_class)
#define pygobject_new (_PyGObject_API->newgobj)
#define pygobject_new_full (_PyGObject_API->newgobj_full)
#define PyGObject_Type (*_PyGObject_API->object_type)
#define pyg_closure_new (_PyGObject_API->closure_new)
#define pygobject_watch_closure (_PyGObject_API->object_watch_closure)
#define pyg_closure_set_exception_handler (_PyGObject_API->closure_set_exception_handler)
......
......@@ -1842,6 +1842,14 @@ pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
return TRUE;
}
if (!pygobject_check (py_arg, &PyGObject_Type)) {
PyObject *repr = PyObject_Repr (py_arg);
PyErr_Format(PyExc_TypeError, "expected GObject but got %s",
PYGLIB_PyUnicode_AsString (repr));
Py_DECREF (repr);
return FALSE;
}
gobj = pygobject_get (py_arg);
if (transfer == GI_TRANSFER_EVERYTHING) {
/* An easy case of adding a new ref that the caller will take ownership of.
......
......@@ -611,3 +611,7 @@ class TestPropertyHoldingObject(unittest.TestCase):
# Clearing should pull it back down
holder.set_property('some-object', None)
self.assertEqual(held.__grefcount__, 1)
def test_set_object_property_to_invalid_type(self):
obj = GIMarshallingTests.PropertiesObject()
self.assertRaises(TypeError, obj.set_property, 'some-object', 'not_an_object')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment