From a93236aa64626bb97a5b8e48306a8525633b9c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 21 Feb 2017 09:58:50 -0500 Subject: [PATCH 1/5] test-env-util: fix typo leading to memleak Partially fixes #5405. --- src/test/test-env-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c index 4f44cf8711..e5cc2a2df8 100644 --- a/src/test/test-env-util.c +++ b/src/test/test-env-util.c @@ -160,8 +160,8 @@ static void test_replace_env(bool braceless) { q = replace_env("BARBAR=$BARBAR=${BARBAR}", (char**) env, flags); assert_se(streq(q, braceless ? "BARBAR==" : "BARBAR=$BARBAR=")); - q = replace_env("BAR=$BAR$BAR${BAR}${BAR}", (char**) env, flags); - assert_se(streq(q, braceless ? "BAR=waldowaldowaldowaldo" : "BAR=$BAR$BARwaldowaldo")); + r = replace_env("BAR=$BAR$BAR${BAR}${BAR}", (char**) env, flags); + assert_se(streq(r, braceless ? "BAR=waldowaldowaldowaldo" : "BAR=$BAR$BARwaldowaldo")); p = replace_env("${BAR}$BAR$BAR", (char**) env, flags); assert_se(streq(p, braceless ? "waldowaldowaldo" : "waldo$BAR$BAR")); From 6fd667e5c97ad8b89cabe2ad7dc6d2d8f4e77891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 21 Feb 2017 10:59:48 -0500 Subject: [PATCH 2/5] mount-tools: silence gcc warning about uninit var --- src/mount/mount-tool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index 4b3cac8a22..b709166aa9 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -1025,7 +1025,7 @@ static int list_devices(void) { j = items + n++; for (c = 0; c < _COLUMN_MAX; c++) { - const char *x; + const char *x = NULL; size_t k; switch (c) { From 2ea8081a5543e608e747426e01bda14f45e9591b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 21 Feb 2017 11:15:19 -0500 Subject: [PATCH 3/5] basic/fileio: fix memleak when discarding an invalid variable Fixes #5405. --- src/basic/fileio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index b9a9f74892..13c03b4f55 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -780,6 +780,7 @@ static int merge_env_file_push( if (!env_name_is_valid(key)) { log_error("%s:%u: invalid variable name \"%s\", ignoring.", strna(filename), line, key); + free(value); return 0; } From 371328dc748c284f5e4e69b7f6554ab14bb63319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 21 Feb 2017 11:15:27 -0500 Subject: [PATCH 4/5] basic/fileio: use IN_SET --- src/basic/fileio.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 13c03b4f55..7c2c2b38f5 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -554,13 +554,14 @@ static int parse_env_file_internal( } } - if (state == PRE_VALUE || - state == VALUE || - state == VALUE_ESCAPE || - state == SINGLE_QUOTE_VALUE || - state == SINGLE_QUOTE_VALUE_ESCAPE || - state == DOUBLE_QUOTE_VALUE || - state == DOUBLE_QUOTE_VALUE_ESCAPE) { + if (IN_SET(state, + PRE_VALUE, + VALUE, + VALUE_ESCAPE, + SINGLE_QUOTE_VALUE, + SINGLE_QUOTE_VALUE_ESCAPE, + DOUBLE_QUOTE_VALUE, + DOUBLE_QUOTE_VALUE_ESCAPE)) { key[n_key] = 0; From 1d046f57207d6af02ba07c79b5c96eb267e61bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 21 Feb 2017 10:49:22 -0500 Subject: [PATCH 5/5] basic/env-util: drop leftover comment --- src/basic/env-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/env-util.c b/src/basic/env-util.c index 2ca64c3301..1ec574e8a0 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -637,7 +637,7 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) { break; nest--; - if (nest == 0) { // || !strchr(e+1, '}')) { + if (nest == 0) { const char *t; _cleanup_free_ char *v = NULL;