core: add nm_dbus_manager_lookup_object_with_type() helper

This makes the non-obvious fact clearer, that when you look up an object
by an untrusted, user-provided path, it might not be the object type you
are looking for. In basically all cases, you need to check that the
result is of the expected type. This helper makes that clearer.
This commit is contained in:
Thomas Haller 2022-02-22 21:13:58 +01:00
parent 256a4cb5d6
commit de61722efe
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 18 additions and 0 deletions

View file

@ -1082,6 +1082,21 @@ nm_dbus_manager_lookup_object(NMDBusManager *self, const char *path)
return obj;
}
gpointer
nm_dbus_manager_lookup_object_with_type(NMDBusManager *self, GType gtype, const char *path)
{
gpointer ptr;
nm_assert(g_type_is_a(gtype, NM_TYPE_DBUS_OBJECT));
nm_assert(gtype != NM_TYPE_DBUS_OBJECT);
ptr = nm_dbus_manager_lookup_object(self, path);
if (!ptr || !G_TYPE_CHECK_INSTANCE_TYPE(ptr, gtype))
return NULL;
return ptr;
}
void
_nm_dbus_manager_obj_export(NMDBusObject *obj)
{

View file

@ -52,6 +52,9 @@ gboolean nm_dbus_manager_is_stopping(NMDBusManager *self);
gpointer nm_dbus_manager_lookup_object(NMDBusManager *self, const char *path);
gpointer
nm_dbus_manager_lookup_object_with_type(NMDBusManager *self, GType gtype, const char *path);
void _nm_dbus_manager_obj_export(NMDBusObject *obj);
void _nm_dbus_manager_obj_unexport(NMDBusObject *obj);
void