]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homed: Add some missing asserts
authorAdrian Vovk <adrianvovk@gmail.com>
Thu, 1 Feb 2024 16:16:44 +0000 (11:16 -0500)
committerLennart Poettering <lennart@poettering.net>
Wed, 14 Feb 2024 08:13:46 +0000 (09:13 +0100)
These functions expect secrets to be passed in (some even dereference
the variables), but fail to assert that they're non-null. So this commit
adds some assertions

src/home/homed-home.c
src/home/user-record-util.c

index fc9dfcff24569c6f4f78effea6e34ab94d030846..8b0df9175ef2b5f7a4cea9e8eba09195a44977e1 100644 (file)
@@ -1323,6 +1323,7 @@ static int home_fixate_internal(
         int r;
 
         assert(h);
+        assert(secret);
         assert(IN_SET(for_state, HOME_FIXATING, HOME_FIXATING_FOR_ACTIVATION, HOME_FIXATING_FOR_ACQUIRE));
 
         r = home_start_work(h, "inspect", h->record, secret);
@@ -1343,6 +1344,7 @@ int home_fixate(Home *h, UserRecord *secret, sd_bus_error *error) {
         int r;
 
         assert(h);
+        assert(secret);
 
         switch (home_get_state(h)) {
         case HOME_ABSENT:
@@ -1370,6 +1372,7 @@ static int home_activate_internal(Home *h, UserRecord *secret, HomeState for_sta
         int r;
 
         assert(h);
+        assert(secret);
         assert(IN_SET(for_state, HOME_ACTIVATING, HOME_ACTIVATING_FOR_ACQUIRE));
 
         r = home_start_work(h, "activate", h->record, secret);
@@ -1384,6 +1387,7 @@ int home_activate(Home *h, UserRecord *secret, sd_bus_error *error) {
         int r;
 
         assert(h);
+        assert(secret);
 
         switch (home_get_state(h)) {
         case HOME_UNFIXATED:
@@ -1417,6 +1421,7 @@ static int home_authenticate_internal(Home *h, UserRecord *secret, HomeState for
         int r;
 
         assert(h);
+        assert(secret);
         assert(IN_SET(for_state, HOME_AUTHENTICATING, HOME_AUTHENTICATING_WHILE_ACTIVE, HOME_AUTHENTICATING_FOR_ACQUIRE));
 
         r = home_start_work(h, "inspect", h->record, secret);
@@ -1432,6 +1437,7 @@ int home_authenticate(Home *h, UserRecord *secret, sd_bus_error *error) {
         int r;
 
         assert(h);
+        assert(secret);
 
         state = home_get_state(h);
         switch (state) {
@@ -1504,6 +1510,7 @@ int home_create(Home *h, UserRecord *secret, sd_bus_error *error) {
         int r;
 
         assert(h);
+        assert(secret);
 
         switch (home_get_state(h)) {
         case HOME_INACTIVE: {
@@ -1840,6 +1847,8 @@ int home_passwd(Home *h,
         int r;
 
         assert(h);
+        assert(new_secret);
+        assert(old_secret);
 
         if (h->signed_locally <= 0) /* Don't allow changing of records not signed only by us */
                 return sd_bus_error_setf(error, BUS_ERROR_HOME_RECORD_SIGNED, "Home %s is signed and cannot be modified locally.", h->user_name);
@@ -1986,6 +1995,7 @@ static int home_unlock_internal(Home *h, UserRecord *secret, HomeState for_state
         int r;
 
         assert(h);
+        assert(secret);
         assert(IN_SET(for_state, HOME_UNLOCKING, HOME_UNLOCKING_FOR_ACQUIRE));
 
         r = home_start_work(h, "unlock", h->record, secret);
@@ -1998,7 +2008,9 @@ static int home_unlock_internal(Home *h, UserRecord *secret, HomeState for_state
 
 int home_unlock(Home *h, UserRecord *secret, sd_bus_error *error) {
         int r;
+
         assert(h);
+        assert(secret);
 
         r = home_ratelimit(h, error);
         if (r < 0)
index 6c427138669abbdf1b23578cee94212b0e9cdb08..8620371ac6a1845dfd9df80efa1e4f7577de91b1 100644 (file)
@@ -1155,6 +1155,7 @@ int user_record_merge_secret(UserRecord *h, UserRecord *secret) {
         int r;
 
         assert(h);
+        assert(secret);
 
         /* Merges the secrets from 'secret' into 'h'. */