chiark / gitweb /
bus: check return value from bus_type_get_alignment/size
[elogind.git] / src / libsystemd-bus / bus-message.c
index 845e2c004056d47abee2073c070bd3079c177e89..c7cc32ec15db8cb10f6bb0f7d55ba23b28ac75ee 100644 (file)
@@ -784,7 +784,7 @@ static void *message_extend_body(sd_bus_message *m, size_t align, size_t sz) {
 
 int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored) {
         struct bus_container *c;
-        size_t sz, align;
+        ssize_t align, sz;
         uint32_t k;
         void *a;
         char *e = NULL;
@@ -1590,10 +1590,12 @@ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) {
         }
 
         default: {
-                size_t sz, align, rindex;
+                ssize_t sz, align;
+                size_t rindex;
 
                 align = bus_type_get_alignment(type);
                 sz = bus_type_get_size(type);
+                assert(align > 0 && sz > 0);
 
                 rindex = m->rindex;
                 r = message_peek_body(m, &rindex, align, sz, &q);
@@ -2392,10 +2394,11 @@ static int message_skip_fields(
                         (*signature)++;
 
                 } else if (bus_type_is_basic(t)) {
-                        size_t align, k;
+                        ssize_t align, k;
 
                         align = bus_type_get_alignment(t);
                         k = bus_type_get_size(t);
+                        assert(align > 0 && k > 0);
 
                         r = message_peek_fields(m, ri, align, k, NULL);
                         if (r < 0)
@@ -3002,3 +3005,38 @@ int bus_message_read_strv_extend(sd_bus_message *m, char ***l) {
 
         return 0;
 }
+
+const char* bus_message_get_arg(sd_bus_message *m, unsigned i) {
+        int r;
+        const char *t;
+        char type;
+
+        assert(m);
+
+        r = sd_bus_message_rewind(m, true);
+        if (r < 0)
+                return NULL;
+
+        while (i > 0) {
+                r = sd_bus_message_peek_type(m, &type, NULL);
+                if (r < 0)
+                        return NULL;
+
+                if (type != SD_BUS_TYPE_STRING &&
+                    type != SD_BUS_TYPE_OBJECT_PATH &&
+                    type != SD_BUS_TYPE_SIGNATURE)
+                        return NULL;
+
+                r = sd_bus_message_read_basic(m, type, &t);
+                if (r < 0)
+                        return NULL;
+
+                i--;
+        }
+
+        r = sd_bus_message_rewind(m, true);
+        if (r < 0)
+                return NULL;
+
+        return t;
+}