diff options
author | Thomas Haller <thaller@redhat.com> | 2022-02-22 21:13:58 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-03-13 12:02:07 +0100 |
commit | de61722efe8a43c282004d4dcb8293fed037368a (patch) | |
tree | 6db8a7c01885129477cb4b77cc2ccba5c0e6f4a7 | |
parent | 256a4cb5d647742b5708db8ab6f38189c751fe4b (diff) |
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.
-rw-r--r-- | src/core/nm-dbus-manager.c | 15 | ||||
-rw-r--r-- | src/core/nm-dbus-manager.h | 3 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/core/nm-dbus-manager.c b/src/core/nm-dbus-manager.c index 2c5f7acee8..7fcbf6cad8 100644 --- a/src/core/nm-dbus-manager.c +++ b/src/core/nm-dbus-manager.c @@ -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) { diff --git a/src/core/nm-dbus-manager.h b/src/core/nm-dbus-manager.h index d7ca78d174..d977f99ffd 100644 --- a/src/core/nm-dbus-manager.h +++ b/src/core/nm-dbus-manager.h @@ -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 |