|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
From cdc2ef6ba88210264f00997e7c99b7f3339c629e Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
From: Lubomir Rintel <lkundrak@v3.sk>
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
Date: Wed, 11 Oct 2017 09:29:30 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
Subject: [PATCH] basic/env-util: drop the validation when deserializing
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
environment
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
The environment variables we've serialized can quite possibly contain
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
characters outside the set allowed by env_assignment_is_valid(). In
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
fact, my environment seems to contain a couple of these:
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
* TERMCAP set by screen contains a '\x7f' character
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
* BASH_FUNC_module%% variable has a '%' character in name
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
Strict check of environment variables name and value certainly makes sense for
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
unit files, but not so much for deserialization of values we already had
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
in our environment.
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
(cherry picked from commit ea43bdd1d7c14e3695a4cc081e4ef4f964160dc1)
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
src/basic/env-util.c | 5 -----
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
src/test/test-env-util.c | 5 +++--
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
2 files changed, 3 insertions(+), 7 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
index fa42edfa96..a8b51e719f 100644
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
--- a/src/basic/env-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
+++ b/src/basic/env-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
@@ -809,10 +809,5 @@ int deserialize_environment(char ***environment, const char *line) {
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
- if (!env_assignment_is_valid(uce)) {
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
- free(uce);
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
- return -EINVAL;
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
- }
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
return strv_env_replace(environment, uce);
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
index 3a2492dc6f..b14d62760f 100644
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
--- a/src/test/test-env-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
+++ b/src/test/test-env-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
@@ -319,10 +319,10 @@ static void test_env_assignment_is_valid(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
static void test_deserialize_environment(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
_cleanup_strv_free_ char **env = strv_new("A=1", NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
- assert_se(deserialize_environment(&env, "env=test") < 0);
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
assert_se(deserialize_environment(&env, "env=B=2") >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
+ assert_se(deserialize_environment(&env, "env=FOO%%=a\\177b\\nc\\td e") >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
- assert_se(strv_equal(env, STRV_MAKE("A=1", "B=2")));
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
+ assert_se(strv_equal(env, STRV_MAKE("A=1", "B=2", "FOO%%=a\177b\nc\td e")));
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
static void test_serialize_environment(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
@@ -334,6 +334,7 @@ static void test_serialize_environment(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
"B=2",
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
"C=ąęółń",
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
"D=D=a\\x0Ab",
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
+ "FOO%%=a\177b\nc\td e",
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
_cleanup_strv_free_ char **env2 = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
35bb94 |
|