]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
userdb: Make lookups return a const pointer
authorSimon McVittie <smcv@collabora.com>
Tue, 30 Jun 2020 18:13:17 +0000 (19:13 +0100)
committerSimon McVittie <smcv@collabora.com>
Tue, 30 Jun 2020 18:13:17 +0000 (19:13 +0100)
This makes it more obvious that the returned pointer points to a
struct owned by the userdb, which must not be freed or have its
contents modified, and is only valid to dereference until the next
modification to the userdb's underlying hash tables (which in practice
means until the lock is released, because after that we have no
guarantees about what might be going on in another thread).

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-userdb-util.c
dbus/dbus-userdb.c
dbus/dbus-userdb.h

index a8608fa6f22e5e5e89a4e0f1d9e2bf9c13139941..18621a17c11ba505500d2530ddd3b717bb180158 100644 (file)
@@ -249,9 +249,9 @@ _dbus_get_user_id_and_primary_group (const DBusString  *username,
  * @param gid the group ID or #DBUS_GID_UNSET
  * @param groupname group name or #NULL 
  * @param error error to fill in
- * @returns the entry in the database
+ * @returns the entry in the database (borrowed, do not free)
  */
-DBusGroupInfo*
+const DBusGroupInfo *
 _dbus_user_database_lookup_group (DBusUserDatabase *db,
                                   dbus_gid_t        gid,
                                   const DBusString *groupname,
@@ -337,6 +337,8 @@ _dbus_user_database_lookup_group (DBusUserDatabase *db,
           return NULL;
         }
       
+      /* Return a borrowed reference to the DBusGroupInfo owned by the
+       * two hash tables */
       return info;
     }
 }
index d3225371fec84bdceb5c23c598c86b3e828bf82d..78169e5ba541f5968a8eb3bc662399d322d2ac98 100644 (file)
@@ -129,9 +129,9 @@ _dbus_is_a_number (const DBusString *str,
  * @param uid the user ID or #DBUS_UID_UNSET
  * @param username username or #NULL 
  * @param error error to fill in
- * @returns the entry in the database
+ * @returns the entry in the database (borrowed, do not free)
  */
-DBusUserInfo*
+const DBusUserInfo *
 _dbus_user_database_lookup (DBusUserDatabase *db,
                             dbus_uid_t        uid,
                             const DBusString *username,
@@ -218,6 +218,8 @@ _dbus_user_database_lookup (DBusUserDatabase *db,
           return NULL;
         }
       
+      /* Return a borrowed pointer to the DBusUserInfo owned by the
+       * hash tables */
       return info;
     }
 }
index 1eb4bd46358f8722c2e1d239debe251f56cb0532..479b2311cb84d1c4fcd028aa6097b123a417e317 100644 (file)
@@ -67,15 +67,15 @@ dbus_bool_t       _dbus_user_database_get_username  (DBusUserDatabase     *db,
                                                      const DBusUserInfo  **info,
                                                      DBusError            *error);
 DBUS_PRIVATE_EXPORT
-DBusUserInfo*  _dbus_user_database_lookup       (DBusUserDatabase *db,
+const DBusUserInfo *_dbus_user_database_lookup  (DBusUserDatabase *db,
                                                  dbus_uid_t        uid,
                                                  const DBusString *username,
                                                  DBusError        *error);
 DBUS_PRIVATE_EXPORT
-DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
-                                                 dbus_gid_t        gid,
-                                                 const DBusString *groupname,
-                                                 DBusError        *error);
+const DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
+                                                       dbus_gid_t        gid,
+                                                       const DBusString *groupname,
+                                                       DBusError        *error);
 DBUS_PRIVATE_EXPORT
 void           _dbus_user_info_free_allocated   (DBusUserInfo     *info);
 DBUS_PRIVATE_EXPORT