tree-wide: add basic validation of --background argument
Check whether the argument of the `--background` option of `systemd-run`, `run0`, `systemd-nspawn`, `systemd-vmspawn`, and `systemd-pty-forward` is either empty or looks like an ANSI color code, and reject invalid values when parsing arguments. We consider a string to look like an ANSI color code if it consists of one or more sequences of ASCII digits separated by semicolons. This permits every valid ANSI color code, and should reject anything that results in garbled output.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "ansi-color.h"
|
||||
#include "bus-util.h"
|
||||
#include "format-table.h"
|
||||
#include "hostname-util.h"
|
||||
@@ -163,3 +164,10 @@ int parse_machine_argument(const char *s, const char **ret_host, BusTransport *r
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_background_argument(const char *s, char **arg) {
|
||||
if (!isempty(s) && !looks_like_ansi_color_code(s))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid --background= argument: %s", s);
|
||||
|
||||
return free_and_strdup_warn(arg, s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user