]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: immediately reject invalid log levels
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Sep 2020 13:42:23 +0000 (15:42 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 12 Sep 2020 08:22:51 +0000 (10:22 +0200)
Symbolic names and number in the appropriate range are allowed
(log_level_from_string() DTRT already).

The target names are more messy, so we leave the verification to the service.

src/systemctl/systemctl.c

index 86de4848a59a11c67cff32ca3e1bdfea517f0b6e..4e31dc7889239f46739fab3124b351fcc99a668d 100644 (file)
@@ -81,6 +81,7 @@
 #include "stat-util.h"
 #include "string-table.h"
 #include "strv.h"
+#include "syslog-util.h"
 #include "sysv-compat.h"
 #include "terminal-util.h"
 #include "tmpfile-util.h"
@@ -6307,6 +6308,12 @@ static int log_setting_internal(sd_bus *bus, const BusLocator* bloc, const char
         int r;
 
         if (value) {
+                if (level) {
+                        if (log_level_from_string(value) < 0)
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                       "\"%s\" is not a valid log level.", value);
+                }
+
                 r = bus_set_property(bus, bloc,
                                      level ? "LogLevel" : "LogTarget",
                                      &error, "s", value);