chiark / gitweb /
bus: fix assert when serializing fixed size struct to gvariant
[elogind.git] / src / libsystemd-bus / bus-message.c
index d6888738e1063989594f2bc762146551f16a3925..9092a6697755fca8d6902217a2661b242afb968f 100644 (file)
@@ -2055,7 +2055,7 @@ static int bus_message_close_struct(sd_bus_message *m, struct bus_container *c,
                                 return r;
                 }
 
-                assert(i <= c->n_offsets);
+                assert(!c->need_offsets || i <= c->n_offsets);
 
                 /* We need to add an offset for each item that has a
                  * variable size and that is not the last one in the
@@ -2067,7 +2067,8 @@ static int bus_message_close_struct(sd_bus_message *m, struct bus_container *c,
                 p += n;
         }
 
-        assert(i == c->n_offsets);
+        assert(!c->need_offsets || i == c->n_offsets);
+        assert(c->need_offsets || n_variable == 0);
 
         if (n_variable <= 0) {
                 a = message_extend_body(m, 1, 0, add_offset);
@@ -5133,6 +5134,14 @@ int bus_message_parse_fields(sd_bus_message *m) {
                 break;
         }
 
+        /* Refuse non-local messages that claim they are local */
+        if (streq_ptr(m->path, "/org/freedesktop/DBus/Local"))
+                return -EBADMSG;
+        if (streq_ptr(m->interface, "org.freedesktop.DBus.Local"))
+                return -EBADMSG;
+        if (streq_ptr(m->sender, "org.freedesktop.DBus.Local"))
+                return -EBADMSG;
+
         m->root_container.end = BUS_MESSAGE_BODY_SIZE(m);
 
         if (BUS_MESSAGE_IS_GVARIANT(m)) {
@@ -5516,3 +5525,13 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
 
         return 0;
 }
+
+int bus_message_append_sender(sd_bus_message *m, const char *sender) {
+        assert(m);
+        assert(sender);
+
+        assert_return(!m->sealed, -EPERM);
+        assert_return(!m->sender, -EPERM);
+
+        return message_append_field_string(m, BUS_MESSAGE_HEADER_SENDER, SD_BUS_TYPE_STRING, sender, &m->sender);
+}