mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 18:20:29 +01:00
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:
parent
256a4cb5d6
commit
de61722efe
2 changed files with 18 additions and 0 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue