]> git.ipfire.org Git - people/ms/systemd.git/commitdiff
manager: enforce limit on accepted number of names
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Apr 2010 00:56:42 +0000 (02:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Apr 2010 00:56:42 +0000 (02:56 +0200)
dbus-manager.c
manager.h
unit.c

index 926324811108143aed43fc6bdfe99b8f03a0f114..47fb403f11b1d2521c55ed59e9b83c3003c852e9 100644 (file)
         "  <property name=\"Version\" type=\"s\" access=\"read\"/>"     \
         "  <property name=\"RunningAs\" type=\"s\" access=\"read\"/>"   \
         "  <property name=\"BootTimestamp\" type=\"t\" access=\"read\"/>" \
-        "  <property name=\"LogLevel\" type=\"s\" access=\"readwrite\"/>" \
-        "  <property name=\"LogTarget\" type=\"s\" access=\"readwrite\"/>" \
+        "  <property name=\"LogLevel\" type=\"s\" access=\"read\"/>"    \
+        "  <property name=\"LogTarget\" type=\"s\" access=\"read\"/>"   \
+        "  <property name=\"NNames\" type=\"u\" access=\"read\"/>"      \
+        "  <property name=\"NJobs\" type=\"u\" access=\"read\"/>"       \
         " </interface>"                                                 \
         BUS_PROPERTIES_INTERFACE                                        \
         BUS_INTROSPECTABLE_INTERFACE
@@ -119,6 +121,36 @@ static int bus_manager_append_log_level(Manager *m, DBusMessageIter *i, const ch
         return 0;
 }
 
+static int bus_manager_append_n_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+        uint32_t u;
+
+        assert(m);
+        assert(i);
+        assert(property);
+
+        u = hashmap_size(m->units);
+
+        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
+                return -ENOMEM;
+
+        return 0;
+}
+
+static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+        uint32_t u;
+
+        assert(m);
+        assert(i);
+        assert(property);
+
+        u = hashmap_size(m->jobs);
+
+        if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
+                return -ENOMEM;
+
+        return 0;
+}
+
 static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection, DBusMessage *message, void *data) {
         Manager *m = data;
 
@@ -128,6 +160,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                 { "org.freedesktop.systemd1.Manager", "BootTimestamp", bus_property_append_uint64,    "t", &m->boot_timestamp },
                 { "org.freedesktop.systemd1.Manager", "LogLevel",      bus_manager_append_log_level,  "s", NULL               },
                 { "org.freedesktop.systemd1.Manager", "LogTarget",     bus_manager_append_log_target, "s", NULL               },
+                { "org.freedesktop.systemd1.Manager", "NNames",        bus_manager_append_n_names,    "u", NULL               },
+                { "org.freedesktop.systemd1.Manager", "NJobs",         bus_manager_append_n_jobs,     "u", NULL               },
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
index bd0c82ee7706d2a94a5abfb5c3211bf73f5d19fa..01490fc18026b6d77d4375f47a1ed2215c0a104b 100644 (file)
--- a/manager.h
+++ b/manager.h
@@ -29,6 +29,9 @@
 
 #include "fdset.h"
 
+/* Enforce upper limit how many names we allow */
+#define MANAGER_MAX_NAMES 2048
+
 typedef struct Manager Manager;
 typedef enum WatchType WatchType;
 typedef struct Watch Watch;
diff --git a/unit.c b/unit.c
index 5c19b3b2da32626b5da0ce15a7850db35e723420..3f2538a694a386cb920b70738b6f6083fb249cae 100644 (file)
--- a/unit.c
+++ b/unit.c
@@ -125,6 +125,11 @@ int unit_add_name(Unit *u, const char *text) {
                 goto fail;
         }
 
+        if (hashmap_size(u->meta.manager->units) >= MANAGER_MAX_NAMES) {
+                r = -E2BIG;
+                goto fail;
+        }
+
         if ((r = set_put(u->meta.names, s)) < 0) {
                 if (r == -EEXIST)
                         r = 0;