]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: warn when importing environment variables with control characters 18129/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Jan 2021 13:20:16 +0000 (14:20 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Jan 2021 13:24:51 +0000 (14:24 +0100)
I don't think it is useful to warn about about environemnt variables where the user
explicitly configured some value. If they went through the effort of escaping the cc
to include it in the setting (e.g. Environment="VAR=\efoo"), and we pass this through,
there isn't anything to warn about. This also applies to 'systemctl set-environment',
where the variable name and value are passed as arguments.

The only case where the warning *might* be useful is where the user might be
surprised by the value. This occurs when importing variables from the inherited
environment, i.e. in 'systemctl import-environment'. In not convinced that this is
useful, since the user better control their shell environment anyway.

$ systemctl import-environment
Calling import-environment without a list of variable names is deprecated.
Environment variable $LESS_TERMCAP_mb contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_md contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_me contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_se contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_so contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_ue contains control characters, importing anyway.
Environment variable $LESS_TERMCAP_us contains control characters, importing anyway.
Environment variable $ZZZ contains control characters, importing anyway.

src/systemctl/systemctl-set-environment.c

index 437236efb41c274ad0736d0099915130c929af53..bfd87c0cdd0af2b0c8515977ad4920172fe3ae67 100644 (file)
@@ -127,6 +127,12 @@ int import_environment(int argc, char *argv[], void *userdata) {
 
                 strv_env_clean_with_callback(copy, invalid_callback, NULL);
 
+                char **e;
+                STRV_FOREACH(e, copy)
+                        if (string_has_cc(*e, NULL))
+                                log_notice("Environment variable $%.*s contains control characters, importing anyway.",
+                                           (int) strcspn(*e, "="), *e);
+
                 r = sd_bus_message_append_strv(m, copy);
 
         } else {
@@ -148,6 +154,10 @@ int import_environment(int argc, char *argv[], void *userdata) {
 
                                 eq = startswith(*b, *a);
                                 if (eq && *eq == '=') {
+                                        if (string_has_cc(eq + 1, NULL))
+                                                log_notice("Environment variable $%.*s contains control characters, importing anyway.",
+                                                           (int) (eq - *b), *b);
+
                                         r = sd_bus_message_append(m, "s", *b);
                                         if (r < 0)
                                                 return bus_log_create_error(r);