systemctl: immediately reject invalid log levels

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-09-11 15:42:23 +02:00
parent 77db9433a7
commit d94bab0805
1 changed files with 7 additions and 0 deletions

View File

@ -81,6 +81,7 @@
#include "stat-util.h" #include "stat-util.h"
#include "string-table.h" #include "string-table.h"
#include "strv.h" #include "strv.h"
#include "syslog-util.h"
#include "sysv-compat.h" #include "sysv-compat.h"
#include "terminal-util.h" #include "terminal-util.h"
#include "tmpfile-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; int r;
if (value) { 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, r = bus_set_property(bus, bloc,
level ? "LogLevel" : "LogTarget", level ? "LogLevel" : "LogTarget",
&error, "s", value); &error, "s", value);