core: when receiving a memory limit via the bus, refuse 0
authorLennart Poettering <lennart@poettering.net>
Wed, 8 Jun 2016 18:04:22 +0000 (20:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 14 Jun 2016 17:50:38 +0000 (19:50 +0200)
When parsing unit files we already refuse unit memory limits of zero, let's
also refuse it when the value is set via the bus.

src/core/dbus-cgroup.c

index 8525fa1..5b94b5e 100644 (file)
@@ -641,7 +641,7 @@ int bus_cgroup_set_property(
 
                 return 1;
 
-        } else if (streq(name, "BlockIOReadBandwidth") || streq(name, "BlockIOWriteBandwidth")) {
+        } else if (STR_IN_SET(name, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) {
                 const char *path;
                 bool read = true;
                 unsigned n = 0;
@@ -835,6 +835,8 @@ int bus_cgroup_set_property(
                 r = sd_bus_message_read(message, "t", &v);
                 if (r < 0)
                         return r;
+                if (v <= 0)
+                        return sd_bus_error_set_errnof(error, EINVAL, "%s= is too small", name);
 
                 if (mode != UNIT_CHECK) {
                         if (streq(name, "MemoryLow"))
@@ -860,6 +862,8 @@ int bus_cgroup_set_property(
                 r = sd_bus_message_read(message, "t", &limit);
                 if (r < 0)
                         return r;
+                if (limit <= 0)
+                        return sd_bus_error_set_errnof(error, EINVAL, "%s= is too small", name);
 
                 if (mode != UNIT_CHECK) {
                         c->memory_limit = limit;