1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-08 08:58:27 +03:00

env-util: fix memory leak (#5962)

If cunescape succeeds, but the assignment is not valid, uce is not freed.
This commit is contained in:
Ronny Chevalier 2017-05-14 16:30:40 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent 0839f42ebf
commit 16eefcafed
2 changed files with 13 additions and 1 deletions

View File

@ -799,8 +799,10 @@ int deserialize_environment(char ***environment, const char *line) {
if (r < 0)
return r;
if (!env_assignment_is_valid(uce))
if (!env_assignment_is_valid(uce)) {
free(uce);
return -EINVAL;
}
return strv_env_replace(environment, uce);
}

View File

@ -314,6 +314,15 @@ static void test_env_assignment_is_valid(void) {
assert_se(!env_assignment_is_valid("głąb=printf \"\x1b]0;<mock-chroot>\x07<mock-chroot>\""));
}
static void test_deserialize_environment(void) {
_cleanup_strv_free_ char **env = strv_new("A=1", NULL);
assert_se(deserialize_environment(&env, "env=test") < 0);
assert_se(deserialize_environment(&env, "env=B=2") >= 0);
assert_se(strv_equal(env, STRV_MAKE("A=1", "B=2")));
}
int main(int argc, char *argv[]) {
test_strv_env_delete();
test_strv_env_get();
@ -330,6 +339,7 @@ int main(int argc, char *argv[]) {
test_env_name_is_valid();
test_env_value_is_valid();
test_env_assignment_is_valid();
test_deserialize_environment();
return 0;
}