summaryrefslogtreecommitdiff
path: root/src/basic/env-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-10-23 14:24:32 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-10-23 15:07:07 +0200
commitff461576de63fd509713618289a698875b1a69ba (patch)
treea75cb95961cb662187edaec31e632538d79d8abd /src/basic/env-util.c
parent451ae5a11adfdd7fa37d05543e97c966a5802924 (diff)
downloadsystemd-ff461576de63fd509713618289a698875b1a69ba.tar.gz
Revert "basic/env-util: (mostly) follow POSIX for what variable names are allowed"
This reverts commit b45c068dd8fac7661a15e99e7cf699ff06010b13. I think the idea was generally sound, but didn't take into account the limitations of show-environment and how it is used. People expect to be able to eval systemctl show-environment output in bash, and no escaping syntax is defined for environment *names* (we only do escaping for *values*). We could skip such problematic variables in 'systemctl show-environment', and only allow them to be inherited directly. But this would be confusing and ugly. The original motivation for this change was that various import operations would fail. a4ccce22d9552dc74b6916cc5ec57f2a0b686b4f changed systemctl to filter invalid variables in import-environment. https://gitlab.gnome.org/GNOME/gnome-session/-/issues/71 does a similar change in GNOME. So those problematic variables should not cause failures, but just be silently ignored. Finally, the environment block is becoming a dumping ground. In my gnome session 'systemctl show-environment --user' includes stuff like PWD, FPATH (from zsh), SHLVL=0 (no idea what that is). This is not directly related to variable names (since all those are allowed under the stricter rules too), but I think we should start pushing people away from running import-environment and towards importing only select variables. https://github.com/systemd/systemd/pull/17188#issuecomment-708676511
Diffstat (limited to 'src/basic/env-util.c')
-rw-r--r--src/basic/env-util.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index 03a2ad83f1..802dff2485 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -21,21 +21,18 @@
DIGITS LETTERS \
"_"
-static bool printable_portable_character(char c) {
- /* POSIX.1-2008 specifies almost all ASCII characters as "portable". (Only DEL is excluded, and
- * additionally NUL and = are not allowed in variable names). We are stricter, and additionally
- * reject BEL, BS, HT, CR, LF, VT, FF and SPACE, i.e. all whitespace. */
-
- return c >= '!' && c <= '~';
-}
-
static bool env_name_is_valid_n(const char *e, size_t n) {
+ const char *p;
+
if (!e)
return false;
if (n <= 0)
return false;
+ if (e[0] >= '0' && e[0] <= '9')
+ return false;
+
/* POSIX says the overall size of the environment block cannot
* be > ARG_MAX, an individual assignment hence cannot be
* either. Discounting the equal sign and trailing NUL this
@@ -44,8 +41,8 @@ static bool env_name_is_valid_n(const char *e, size_t n) {
if (n > (size_t) sysconf(_SC_ARG_MAX) - 2)
return false;
- for (const char *p = e; p < e + n; p++)
- if (!printable_portable_character(*p) || *p == '=')
+ for (p = e; p < e + n; p++)
+ if (!strchr(VALID_BASH_ENV_NAME_CHARS, *p))
return false;
return true;