From 1ff2852a188de9235a293a347683c4c012708fe8 Mon Sep 17 00:00:00 2001
From: Lubomir Rintel <lkundrak@v3.sk>
Date: Wed, 11 Oct 2017 15:05:38 +0200
Subject: [PATCH] basic/env-util: don't relax unesaping of serialized
environment strings
We wrote them ourselves -- they shouldn't contain invalid sequences.
(cherry picked from commit c7d797bbdfaccd950988698823e17103f418a3c5)
---
src/basic/env-util.c | 2 +-
src/test/test-env-util.c | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index a8b51e719f..0da10de0c8 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -805,7 +805,7 @@ int deserialize_environment(char ***environment, const char *line) {
assert(environment);
assert(startswith(line, "env="));
- r = cunescape(line + 4, UNESCAPE_RELAX, &uce);
+ r = cunescape(line + 4, 0, &uce);
if (r < 0)
return r;
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c
index b14d62760f..a76f691b79 100644
--- a/src/test/test-env-util.c
+++ b/src/test/test-env-util.c
@@ -323,6 +323,9 @@ static void test_deserialize_environment(void) {
assert_se(deserialize_environment(&env, "env=FOO%%=a\\177b\\nc\\td e") >= 0);
assert_se(strv_equal(env, STRV_MAKE("A=1", "B=2", "FOO%%=a\177b\nc\td e")));
+
+ assert_se(deserialize_environment(&env, "env=foo\\") < 0);
+ assert_se(deserialize_environment(&env, "env=bar\\_baz") < 0);
}
static void test_serialize_environment(void) {