chiark / gitweb /
bus: when parsing enforce maximum container depth
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Mar 2013 01:32:34 +0000 (02:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 22 Mar 2013 01:32:34 +0000 (02:32 +0100)
src/libsystemd-bus/bus-internal.h
src/libsystemd-bus/bus-message.c
src/libsystemd-bus/sd-bus.h

index 3c2478e8fd0216cbefbd767c2ed1a1647e9c146f..d0b7b5658dbc479f4336dd80eb9e21560c31a905 100644 (file)
@@ -118,6 +118,8 @@ static inline void bus_unrefp(sd_bus **b) {
 #define BUS_MESSAGE_SIZE_MAX (64*1024*1024)
 #define BUS_AUTH_SIZE_MAX (64*1024)
 
+#define BUS_CONTAINER_DEPTH 128
+
 /* Defined by the specification as maximum size of an array in
  * bytes */
 #define BUS_ARRAY_MAX_SIZE 67108864
index ec98de313239cc27cb4f314dc50e91bb7e18d42b..74ea71ec0d62bb6749898a384c0d993ed785c63f 100644 (file)
@@ -1741,6 +1741,25 @@ int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *con
         if (!contents)
                 return -EINVAL;
 
+        /*
+         * We enforce a global limit on container depth, that is much
+         * higher than the 32 structs and 32 arrays the specification
+         * mandates. This is simpler to implement for us, and we need
+         * this only to ensure our container array doesn't grow
+         * without bounds. We are happy to return any data from a
+         * message as long as the data itself is valid, even if the
+         * overall message might be not.
+         *
+         * Note that the message signature is validated when
+         * parsing the headers, and that validation does check the
+         * 32/32 limit.
+         *
+         * Note that the specification defines no limits on the depth
+         * of stacked variants, but we do.
+         */
+        if (m->n_containers >= BUS_CONTAINER_DEPTH)
+                return -EBADMSG;
+
         w = realloc(m->containers, sizeof(struct bus_container) * (m->n_containers + 1));
         if (!w)
                 return -ENOMEM;
index adc7f8e2bdd55553d0ad3a3e163f72a864d2c377..8af1e85aae719f0ee38a5623f7cee9e8166ce025 100644 (file)
@@ -32,7 +32,6 @@
  * - make unix fd passing work
  * - add page donation logic
  * - api for appending/reading fixed arrays
- * - always verify container depth
  * - merge busctl into systemctl or so?
  * - add object handlers
  * - implicitly add stub introspection calls