chiark / gitweb /
bus-proxyd: add some asserts
authorTom Gundersen <teg@jklm.no>
Thu, 25 Sep 2014 13:49:43 +0000 (15:49 +0200)
committerTom Gundersen <teg@jklm.no>
Thu, 25 Sep 2014 13:59:24 +0000 (15:59 +0200)
Both as documentation, and to make Coverity happy.

Fixes CID #1241495 and #1241496.

src/bus-proxyd/bus-policy.c
src/bus-proxyd/bus-proxyd.c

index 165e763f57ba0b7f8bacc0516ade966541cf2cf6..0de7680d4bf238105073822048273b8a09a3ff99 100644 (file)
@@ -611,11 +611,16 @@ struct policy_check_filter {
 
 static int is_permissive(PolicyItem *i) {
 
+        assert(i);
+
         return (i->type == POLICY_ITEM_ALLOW) ? ALLOW : DENY;
 }
 
 static int check_policy_item(PolicyItem *i, const struct policy_check_filter *filter) {
 
+        assert(i);
+        assert(filter);
+
         switch (i->class) {
         case POLICY_ITEM_SEND:
         case POLICY_ITEM_RECV:
@@ -643,21 +648,29 @@ static int check_policy_item(PolicyItem *i, const struct policy_check_filter *fi
                 return is_permissive(i);
 
         case POLICY_ITEM_OWN:
+                assert(filter->member);
+
                 if (streq(i->name, filter->member))
                         return is_permissive(i);
                 break;
 
         case POLICY_ITEM_OWN_PREFIX:
+                assert(filter->member);
+
                 if (startswith(i->name, filter->member))
                         return is_permissive(i);
                 break;
 
         case POLICY_ITEM_USER:
+                assert(filter->ucred);
+
                 if ((streq_ptr(i->name, "*") || (i->uid_valid && i->uid == filter->ucred->uid)))
                         return is_permissive(i);
                 break;
 
         case POLICY_ITEM_GROUP:
+                assert(filter->ucred);
+
                 if ((streq_ptr(i->name, "*") || (i->gid_valid && i->gid == filter->ucred->gid)))
                         return is_permissive(i);
                 break;
@@ -675,6 +688,9 @@ static int check_policy_items(PolicyItem *items, const struct policy_check_filte
         PolicyItem *i;
         int r, ret = DUNNO;
 
+        assert(items);
+        assert(filter);
+
         /* Check all policies in a set - a broader one might be followed by a more specific one,
          * and the order of rules in policy definitions matters */
         LIST_FOREACH(items, i, items) {
@@ -694,6 +710,9 @@ static int policy_check(Policy *p, const struct policy_check_filter *filter) {
         PolicyItem *items;
         int r;
 
+        assert(p);
+        assert(filter);
+
         /*
          * The policy check is implemented by the following logic:
          *
index a5387bb234a27e684cc4532442ddd2d29fa12c6a..6a0fc7edfba435d2359bda5c99b691d18e241431 100644 (file)
@@ -373,6 +373,8 @@ static int synthetic_reply_method_error(sd_bus_message *call, const sd_bus_error
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
+        assert(call);
+
         if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
                 return 0;
 
@@ -387,6 +389,8 @@ static int synthetic_reply_method_errno(sd_bus_message *call, int error, const s
 
         _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
 
+        assert(call);
+
         if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
                 return 0;
 
@@ -402,6 +406,8 @@ static int synthetic_reply_method_return(sd_bus_message *call, const char *types
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
+        assert(call);
+
         if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
                 return 0;
 
@@ -426,6 +432,8 @@ static int synthetic_reply_return_strv(sd_bus_message *call, char **l) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
+        assert(call);
+
         r = sd_bus_message_new_method_return(call, &m);
         if (r < 0)
                 return synthetic_reply_method_errno(call, r, NULL);