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:
Daniel Hast
2025-10-25 09:56:31 +09:00
committed by Yu Watanabe
parent 6fac8bb9b1
commit 101dd41cb4
9 changed files with 75 additions and 5 deletions
+1 -1
View File
@@ -1529,7 +1529,7 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_BACKGROUND:
r = free_and_strdup_warn(&arg_background, optarg);
r = parse_background_argument(optarg, &arg_background);
if (r < 0)
return r;
break;