From b356b73f5c5162e8539026b4fdda50d148c127f1 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: May 17 2013 12:01:58 +0000 Subject: Pick fileio fixes for environment files (#964132). Drop isdn.service from default preset (Lennart, #959793). --- diff --git a/0053-fileio-also-escape-and-when-writing-out-env-vars.patch b/0053-fileio-also-escape-and-when-writing-out-env-vars.patch new file mode 100644 index 0000000..2d8a5a2 --- /dev/null +++ b/0053-fileio-also-escape-and-when-writing-out-env-vars.patch @@ -0,0 +1,29 @@ +From c79393bba5b039537870f421d65cd0625e135149 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Mantas=20Mikul=C4=97nas?= +Date: Sun, 14 Apr 2013 14:54:09 +0300 +Subject: [PATCH] fileio: also escape $ and ` when writing out env vars + +These are also considered special by sh and bash. +(cherry picked from commit ced2d10a28cff3bab6fb613652db5abde8ed940e) +--- + src/shared/fileio.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/shared/fileio.c b/src/shared/fileio.c +index 400a416..617afea 100644 +--- a/src/shared/fileio.c ++++ b/src/shared/fileio.c +@@ -529,11 +529,11 @@ static void write_env_var(FILE *f, const char *v) { + p++; + fwrite(v, 1, p-v, f); + +- if (string_has_cc(p) || chars_intersect(p, WHITESPACE "\'\"\\")) { ++ if (string_has_cc(p) || chars_intersect(p, WHITESPACE "\'\"\\`$")) { + fputc('\"', f); + + for (; *p; p++) { +- if (strchr("\'\"\\", *p)) ++ if (strchr("\'\"\\`$", *p)) + fputc('\\', f); + + fputc(*p, f); diff --git a/0054-fileio-parse_env_file_internal-fix-environment-file-.patch b/0054-fileio-parse_env_file_internal-fix-environment-file-.patch new file mode 100644 index 0000000..4262bb1 --- /dev/null +++ b/0054-fileio-parse_env_file_internal-fix-environment-file-.patch @@ -0,0 +1,105 @@ +From 9ef15e237b8fda40d1a40d0cc8a25e99358bd163 Mon Sep 17 00:00:00 2001 +From: Harald Hoyer +Date: Wed, 17 Apr 2013 11:02:56 +0200 +Subject: [PATCH] fileio:parse_env_file_internal() fix environment file parsing + +parse_env_file_internal() could not parse the following lines correctly: + +export key="val" +key="val"#comment +(cherry picked from commit db5372091664c977a937f6bc0fe4484363be0669) +--- + src/shared/fileio.c | 6 ++++-- + src/test/test-fileio.c | 20 +++++++++++++++----- + 2 files changed, 19 insertions(+), 7 deletions(-) + +diff --git a/src/shared/fileio.c b/src/shared/fileio.c +index 617afea..3f242ed 100644 +--- a/src/shared/fileio.c ++++ b/src/shared/fileio.c +@@ -209,7 +209,9 @@ static int parse_env_file_internal( + switch (state) { + + case PRE_KEY: +- if (strchr(COMMENTS, c)) ++ if (startswith(p, "export ")) ++ p+=6; ++ else if (strchr(COMMENTS, c)) + state = COMMENT; + else if (!strchr(WHITESPACE, c)) { + state = KEY; +@@ -255,7 +257,7 @@ static int parse_env_file_internal( + break; + + case PRE_VALUE: +- if (strchr(newline, c)) { ++ if (strchr(newline, c) || strchr(COMMENTS, c)) { + state = PRE_KEY; + key[n_key] = 0; + +diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c +index 7adf2ef..994b89b 100644 +--- a/src/test/test-fileio.c ++++ b/src/test/test-fileio.c +@@ -31,7 +31,7 @@ static void test_parse_env_file(void) { + char t[] = "/tmp/test-parse-env-file-XXXXXX"; + int fd, r; + FILE *f; +- _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL, *six = NULL, *seven = NULL; ++ _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL, *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL; + _cleanup_strv_free_ char **a = NULL, **b = NULL; + char **i; + unsigned k; +@@ -53,7 +53,9 @@ static void test_parse_env_file(void) { + "five = \'55\\\'55\' \"FIVE\" cinco \n" + "six = seis sechs\\\n" + " sis\n" +- "seven=", f); ++ "export seven=\"sevenval\"#comment\n" ++ "eight=#comment\n" ++ "nine=", f); + + fflush(f); + fclose(f); +@@ -67,6 +69,8 @@ static void test_parse_env_file(void) { + "five", &five, + "six", &six, + "seven", &seven, ++ "eight", &eight, ++ "nine", &nine, + NULL); + + assert_se(r >= 0); +@@ -78,6 +82,8 @@ static void test_parse_env_file(void) { + log_info("five=[%s]", strna(five)); + log_info("six=[%s]", strna(six)); + log_info("seven=[%s]", strna(seven)); ++ log_info("eight=[%s]", strna(eight)); ++ log_info("nine=[%s]", strna(nine)); + + assert_se(streq(one, "BAR")); + assert_se(streq(two, "bar")); +@@ -85,7 +91,9 @@ static void test_parse_env_file(void) { + assert_se(streq(four, "44\"44")); + assert_se(streq(five, "55\'55FIVEcinco")); + assert_se(streq(six, "seis sechs sis")); +- assert_se(seven == NULL); ++ assert_se(streq(seven, "sevenval")); ++ assert_se(eight == NULL); ++ assert_se(nine == NULL); + + r = load_env_file(t, NULL, &a); + assert_se(r >= 0); +@@ -99,8 +107,10 @@ static void test_parse_env_file(void) { + assert_se(streq(a[3], "four=44\"44")); + assert_se(streq(a[4], "five=55\'55FIVEcinco")); + assert_se(streq(a[5], "six=seis sechs sis")); +- assert_se(streq(a[6], "seven=")); +- assert_se(a[7] == NULL); ++ assert_se(streq(a[6], "seven=sevenval")); ++ assert_se(streq(a[7], "eight=")); ++ assert_se(streq(a[8], "nine=")); ++ assert_se(a[9] == NULL); + + r = write_env_file("/tmp/test-fileio", a); + assert_se(r >= 0); diff --git a/0055-core-execute-report-invalid-environment-variables-fr.patch b/0055-core-execute-report-invalid-environment-variables-fr.patch new file mode 100644 index 0000000..5581567 --- /dev/null +++ b/0055-core-execute-report-invalid-environment-variables-fr.patch @@ -0,0 +1,292 @@ +From 66435e2e05c4e9a7570ac245cdbd064edf88b1ba Mon Sep 17 00:00:00 2001 +From: Harald Hoyer +Date: Wed, 17 Apr 2013 15:25:02 +0200 +Subject: [PATCH] core/execute: report invalid environment variables from files + +Because "export key=val" is not supported by systemd, an error is logged +where the invalid assignment is coming from. + +Introduce strv_env_clean_log() to log invalid environment assignments, +where logging is possible and allowed. + +parse_env_file_internal() is modified to allow WHITESPACE in keys, to +report the issues later on. +(cherry picked from commit ebc05a09ad6d1672cf4f426ee4252cf495daa139) +--- + src/core/execute.c | 2 ++ + src/shared/env-util.c | 8 ++++- + src/shared/env-util.h | 1 + + src/shared/fileio.c | 34 +++++++++------------- + src/test/test-fileio.c | 79 ++++++++++++++++++++++++++++---------------------- + 5 files changed, 68 insertions(+), 56 deletions(-) + +diff --git a/src/core/execute.c b/src/core/execute.c +index 5083af9..4b29d8e 100644 +--- a/src/core/execute.c ++++ b/src/core/execute.c +@@ -1756,6 +1756,8 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { + strv_free(r); + return k; + } ++ /* Log invalid environment variables with filename */ ++ p = strv_env_clean_log(p, pglob.gl_pathv[n]); + + if (r == NULL) + r = p; +diff --git a/src/shared/env-util.c b/src/shared/env-util.c +index 54988e6..d3d4c59 100644 +--- a/src/shared/env-util.c ++++ b/src/shared/env-util.c +@@ -376,7 +376,7 @@ char *strv_env_get(char **l, const char *name) { + return strv_env_get_n(l, name, strlen(name)); + } + +-char **strv_env_clean(char **e) { ++char **strv_env_clean_log(char **e, const char *message) { + char **p, **q; + int k = 0; + +@@ -385,6 +385,8 @@ char **strv_env_clean(char **e) { + bool duplicate = false; + + if (!env_assignment_is_valid(*p)) { ++ if (message) ++ log_error("Ignoring invalid environment '%s': %s", *p, message); + free(*p); + continue; + } +@@ -407,3 +409,7 @@ char **strv_env_clean(char **e) { + e[k] = NULL; + return e; + } ++ ++char **strv_env_clean(char **e) { ++ return strv_env_clean_log(e, NULL); ++} +diff --git a/src/shared/env-util.h b/src/shared/env-util.h +index 9449576..b2e520c 100644 +--- a/src/shared/env-util.h ++++ b/src/shared/env-util.h +@@ -30,6 +30,7 @@ bool env_assignment_is_valid(const char *e); + + bool strv_env_is_valid(char **e); + char **strv_env_clean(char **l); ++char **strv_env_clean_log(char **e, const char *message); + + bool strv_env_name_or_assignment_is_valid(char **l); + +diff --git a/src/shared/fileio.c b/src/shared/fileio.c +index 3f242ed..4390726 100644 +--- a/src/shared/fileio.c ++++ b/src/shared/fileio.c +@@ -184,7 +184,6 @@ static int parse_env_file_internal( + enum { + PRE_KEY, + KEY, +- PRE_EQUAL, + PRE_VALUE, + VALUE, + VALUE_ESCAPE, +@@ -209,9 +208,7 @@ static int parse_env_file_internal( + switch (state) { + + case PRE_KEY: +- if (startswith(p, "export ")) +- p+=6; +- else if (strchr(COMMENTS, c)) ++ if (strchr(COMMENTS, c)) + state = COMMENT; + else if (!strchr(WHITESPACE, c)) { + state = KEY; +@@ -228,9 +225,7 @@ static int parse_env_file_internal( + if (strchr(newline, c)) { + state = PRE_KEY; + n_key = 0; +- } else if (strchr(WHITESPACE, c)) +- state = PRE_EQUAL; +- else if (c == '=') ++ } else if (c == '=') + state = PRE_VALUE; + else { + if (!greedy_realloc((void**) &key, &key_alloc, n_key+2)) { +@@ -243,19 +238,6 @@ static int parse_env_file_internal( + + break; + +- case PRE_EQUAL: +- if (strchr(newline, c)) { +- state = PRE_KEY; +- n_key = 0; +- } else if (c == '=') +- state = PRE_VALUE; +- else if (!strchr(WHITESPACE, c)) { +- n_key = 0; +- state = COMMENT; +- } +- +- break; +- + case PRE_VALUE: + if (strchr(newline, c) || strchr(COMMENTS, c)) { + state = PRE_KEY; +@@ -264,6 +246,10 @@ static int parse_env_file_internal( + if (value) + value[n_value] = 0; + ++ /* strip trailing whitespace from key */ ++ while(strchr(WHITESPACE, key[--n_key])) ++ key[n_key]=0; ++ + r = push(key, value, userdata); + if (r < 0) + goto fail; +@@ -302,6 +288,10 @@ static int parse_env_file_internal( + if (last_whitespace != (size_t) -1) + value[last_whitespace] = 0; + ++ /* strip trailing whitespace from key */ ++ while(strchr(WHITESPACE, key[--n_key])) ++ key[n_key]=0; ++ + r = push(key, value, userdata); + if (r < 0) + goto fail; +@@ -426,6 +416,10 @@ static int parse_env_file_internal( + if (value) + value[n_value] = 0; + ++ /* strip trailing whitespace from key */ ++ while(strchr(WHITESPACE, key[--n_key])) ++ key[n_key]=0; ++ + r = push(key, value, userdata); + if (r < 0) + goto fail; +diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c +index 994b89b..2a74104 100644 +--- a/src/test/test-fileio.c ++++ b/src/test/test-fileio.c +@@ -26,12 +26,14 @@ + #include "util.h" + #include "fileio.h" + #include "strv.h" ++#include "env-util.h" + + static void test_parse_env_file(void) { + char t[] = "/tmp/test-parse-env-file-XXXXXX"; + int fd, r; + FILE *f; +- _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL, *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL; ++ _cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL, ++ *six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL; + _cleanup_strv_free_ char **a = NULL, **b = NULL; + char **i; + unsigned k; +@@ -53,13 +55,46 @@ static void test_parse_env_file(void) { + "five = \'55\\\'55\' \"FIVE\" cinco \n" + "six = seis sechs\\\n" + " sis\n" +- "export seven=\"sevenval\"#comment\n" ++ "seven=\"sevenval\"#comment\n" + "eight=#comment\n" +- "nine=", f); ++ "export nine=nineval\n" ++ "ten=", f); + + fflush(f); + fclose(f); + ++ r = load_env_file(t, NULL, &a); ++ assert_se(r >= 0); ++ ++ STRV_FOREACH(i, a) ++ log_info("Got: <%s>", *i); ++ ++ assert_se(streq(a[0], "one=BAR")); ++ assert_se(streq(a[1], "two=bar")); ++ assert_se(streq(a[2], "three=333\nxxxx")); ++ assert_se(streq(a[3], "four=44\"44")); ++ assert_se(streq(a[4], "five=55\'55FIVEcinco")); ++ assert_se(streq(a[5], "six=seis sechs sis")); ++ assert_se(streq(a[6], "seven=sevenval")); ++ assert_se(streq(a[7], "eight=")); ++ assert_se(streq(a[8], "export nine=nineval")); ++ assert_se(streq(a[9], "ten=")); ++ assert_se(a[10] == NULL); ++ ++ strv_env_clean_log(a, "/tmp/test-fileio"); ++ ++ r = write_env_file("/tmp/test-fileio", a); ++ assert_se(r >= 0); ++ ++ r = load_env_file("/tmp/test-fileio", NULL, &b); ++ assert_se(r >= 0); ++ ++ k = 0; ++ STRV_FOREACH(i, b) { ++ log_info("Got2: <%s>", *i); ++ assert_se(streq(*i, a[k++])); ++ } ++ + r = parse_env_file( + t, NULL, + "one", &one, +@@ -70,7 +105,8 @@ static void test_parse_env_file(void) { + "six", &six, + "seven", &seven, + "eight", &eight, +- "nine", &nine, ++ "export nine", &nine, ++ "ten", &ten, + NULL); + + assert_se(r >= 0); +@@ -83,7 +119,8 @@ static void test_parse_env_file(void) { + log_info("six=[%s]", strna(six)); + log_info("seven=[%s]", strna(seven)); + log_info("eight=[%s]", strna(eight)); +- log_info("nine=[%s]", strna(nine)); ++ log_info("export nine=[%s]", strna(nine)); ++ log_info("ten=[%s]", strna(nine)); + + assert_se(streq(one, "BAR")); + assert_se(streq(two, "bar")); +@@ -93,36 +130,8 @@ static void test_parse_env_file(void) { + assert_se(streq(six, "seis sechs sis")); + assert_se(streq(seven, "sevenval")); + assert_se(eight == NULL); +- assert_se(nine == NULL); +- +- r = load_env_file(t, NULL, &a); +- assert_se(r >= 0); +- +- STRV_FOREACH(i, a) +- log_info("Got: <%s>", *i); +- +- assert_se(streq(a[0], "one=BAR")); +- assert_se(streq(a[1], "two=bar")); +- assert_se(streq(a[2], "three=333\nxxxx")); +- assert_se(streq(a[3], "four=44\"44")); +- assert_se(streq(a[4], "five=55\'55FIVEcinco")); +- assert_se(streq(a[5], "six=seis sechs sis")); +- assert_se(streq(a[6], "seven=sevenval")); +- assert_se(streq(a[7], "eight=")); +- assert_se(streq(a[8], "nine=")); +- assert_se(a[9] == NULL); +- +- r = write_env_file("/tmp/test-fileio", a); +- assert_se(r >= 0); +- +- r = load_env_file("/tmp/test-fileio", NULL, &b); +- assert_se(r >= 0); +- +- k = 0; +- STRV_FOREACH(i, b) { +- log_info("Got2: <%s>", *i); +- assert_se(streq(*i, a[k++])); +- } ++ assert_se(streq(nine, "nineval")); ++ assert_se(ten == NULL); + + unlink(t); + unlink("/tmp/test-fileio"); diff --git a/0056-fileio.c-do-not-parse-comments-after-non-whitespace-.patch b/0056-fileio.c-do-not-parse-comments-after-non-whitespace-.patch new file mode 100644 index 0000000..8a2f087 --- /dev/null +++ b/0056-fileio.c-do-not-parse-comments-after-non-whitespace-.patch @@ -0,0 +1,134 @@ +From a422a32de4fa85c5cdbd20a8be0c963e4904cb7a Mon Sep 17 00:00:00 2001 +From: Harald Hoyer +Date: Thu, 18 Apr 2013 10:15:25 +0200 +Subject: [PATCH] fileio.c: do not parse comments after non-whitespace chars + +systemd does not want to understand comments after the first +non-whitespace char occured. + +key=foo #comment will result into key == "foo #comment" +key="foo" #comment will result into key == "foo#comment" +"key= #comment" will result into key == "#comment" +"key #comment" is an invalid line +(cherry picked from commit 98f59e59e0c31ffcb953d3a7dba0da5e6f2f55f7) +--- + src/shared/fileio.c | 9 +++++---- + src/test/test-fileio.c | 26 ++++++++++++++------------ + 2 files changed, 19 insertions(+), 16 deletions(-) + +diff --git a/src/shared/fileio.c b/src/shared/fileio.c +index 4390726..f654af7 100644 +--- a/src/shared/fileio.c ++++ b/src/shared/fileio.c +@@ -239,7 +239,7 @@ static int parse_env_file_internal( + break; + + case PRE_VALUE: +- if (strchr(newline, c) || strchr(COMMENTS, c)) { ++ if (strchr(newline, c)) { + state = PRE_KEY; + key[n_key] = 0; + +@@ -247,7 +247,7 @@ static int parse_env_file_internal( + value[n_value] = 0; + + /* strip trailing whitespace from key */ +- while(strchr(WHITESPACE, key[--n_key])) ++ while(n_key && strchr(WHITESPACE, key[--n_key])) + key[n_key]=0; + + r = push(key, value, userdata); +@@ -279,6 +279,7 @@ static int parse_env_file_internal( + case VALUE: + if (strchr(newline, c)) { + state = PRE_KEY; ++ + key[n_key] = 0; + + if (value) +@@ -289,7 +290,7 @@ static int parse_env_file_internal( + value[last_whitespace] = 0; + + /* strip trailing whitespace from key */ +- while(strchr(WHITESPACE, key[--n_key])) ++ while(n_key && strchr(WHITESPACE, key[--n_key])) + key[n_key]=0; + + r = push(key, value, userdata); +@@ -417,7 +418,7 @@ static int parse_env_file_internal( + value[n_value] = 0; + + /* strip trailing whitespace from key */ +- while(strchr(WHITESPACE, key[--n_key])) ++ while(n_key && strchr(WHITESPACE, key[--n_key])) + key[n_key]=0; + + r = push(key, value, userdata); +diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c +index 2a74104..d56f7cc 100644 +--- a/src/test/test-fileio.c ++++ b/src/test/test-fileio.c +@@ -47,16 +47,18 @@ static void test_parse_env_file(void) { + fputs("one=BAR \n" + "# comment\n" + " # comment \n" ++ " ; comment \n" + " two = bar \n" + "invalid line\n" ++ "invalid line #comment\n" + "three = \"333\n" + "xxxx\"\n" + "four = \'44\\\"44\'\n" + "five = \'55\\\'55\' \"FIVE\" cinco \n" + "six = seis sechs\\\n" + " sis\n" +- "seven=\"sevenval\"#comment\n" +- "eight=#comment\n" ++ "seven=\"sevenval\" #nocomment\n" ++ "eight=eightval #nocomment\n" + "export nine=nineval\n" + "ten=", f); + +@@ -75,20 +77,14 @@ static void test_parse_env_file(void) { + assert_se(streq(a[3], "four=44\"44")); + assert_se(streq(a[4], "five=55\'55FIVEcinco")); + assert_se(streq(a[5], "six=seis sechs sis")); +- assert_se(streq(a[6], "seven=sevenval")); +- assert_se(streq(a[7], "eight=")); ++ assert_se(streq(a[6], "seven=sevenval#nocomment")); ++ assert_se(streq(a[7], "eight=eightval #nocomment")); + assert_se(streq(a[8], "export nine=nineval")); + assert_se(streq(a[9], "ten=")); + assert_se(a[10] == NULL); + + strv_env_clean_log(a, "/tmp/test-fileio"); + +- r = write_env_file("/tmp/test-fileio", a); +- assert_se(r >= 0); +- +- r = load_env_file("/tmp/test-fileio", NULL, &b); +- assert_se(r >= 0); +- + k = 0; + STRV_FOREACH(i, b) { + log_info("Got2: <%s>", *i); +@@ -128,11 +124,17 @@ static void test_parse_env_file(void) { + assert_se(streq(four, "44\"44")); + assert_se(streq(five, "55\'55FIVEcinco")); + assert_se(streq(six, "seis sechs sis")); +- assert_se(streq(seven, "sevenval")); +- assert_se(eight == NULL); ++ assert_se(streq(seven, "sevenval#nocomment")); ++ assert_se(streq(eight, "eightval #nocomment")); + assert_se(streq(nine, "nineval")); + assert_se(ten == NULL); + ++ r = write_env_file("/tmp/test-fileio", a); ++ assert_se(r >= 0); ++ ++ r = load_env_file("/tmp/test-fileio", NULL, &b); ++ assert_se(r >= 0); ++ + unlink(t); + unlink("/tmp/test-fileio"); + } diff --git a/0057-fileio-unify-how-we-chop-off-whitespace-from-key-and.patch b/0057-fileio-unify-how-we-chop-off-whitespace-from-key-and.patch new file mode 100644 index 0000000..69dbcc7 --- /dev/null +++ b/0057-fileio-unify-how-we-chop-off-whitespace-from-key-and.patch @@ -0,0 +1,127 @@ +From 846dd695edba75bb96762116cae2092f691161bd Mon Sep 17 00:00:00 2001 +From: Lennart Poettering +Date: Wed, 24 Apr 2013 15:44:28 -0300 +Subject: [PATCH] fileio: unify how we chop off whitespace from key and value + in parse_env_file_internal() (cherry picked from commit + 2b77f67e78827cc7e85fb43b05d3e1623b31a1bf) + +Conflicts: + TODO +--- + src/shared/fileio.c | 46 ++++++++++++++++++++++++++++++---------------- + 1 file changed, 30 insertions(+), 16 deletions(-) + +diff --git a/src/shared/fileio.c b/src/shared/fileio.c +index f654af7..18a3645 100644 +--- a/src/shared/fileio.c ++++ b/src/shared/fileio.c +@@ -177,7 +177,7 @@ static int parse_env_file_internal( + void *userdata) { + + _cleanup_free_ char *contents = NULL, *key = NULL; +- size_t key_alloc = 0, n_key = 0, value_alloc = 0, n_value = 0, last_whitespace = (size_t) -1; ++ size_t key_alloc = 0, n_key = 0, value_alloc = 0, n_value = 0, last_value_whitespace = (size_t) -1, last_key_whitespace = (size_t) -1; + char *p, *value = NULL; + int r; + +@@ -212,6 +212,8 @@ static int parse_env_file_internal( + state = COMMENT; + else if (!strchr(WHITESPACE, c)) { + state = KEY; ++ last_key_whitespace = (size_t) -1; ++ + if (!greedy_realloc((void**) &key, &key_alloc, n_key+2)) { + r = -ENOMEM; + goto fail; +@@ -225,9 +227,15 @@ static int parse_env_file_internal( + if (strchr(newline, c)) { + state = PRE_KEY; + n_key = 0; +- } else if (c == '=') ++ } else if (c == '=') { + state = PRE_VALUE; +- else { ++ last_value_whitespace = (size_t) -1; ++ } else { ++ if (!strchr(WHITESPACE, c)) ++ last_key_whitespace = (size_t) -1; ++ else if (last_key_whitespace == (size_t) -1) ++ last_key_whitespace = n_key; ++ + if (!greedy_realloc((void**) &key, &key_alloc, n_key+2)) { + r = -ENOMEM; + goto fail; +@@ -247,8 +255,8 @@ static int parse_env_file_internal( + value[n_value] = 0; + + /* strip trailing whitespace from key */ +- while(n_key && strchr(WHITESPACE, key[--n_key])) +- key[n_key]=0; ++ if (last_key_whitespace != (size_t) -1) ++ key[last_key_whitespace] = 0; + + r = push(key, value, userdata); + if (r < 0) +@@ -257,6 +265,7 @@ static int parse_env_file_internal( + n_key = 0; + value = NULL; + value_alloc = n_value = 0; ++ + } else if (c == '\'') + state = SINGLE_QUOTE_VALUE; + else if (c == '\"') +@@ -285,13 +294,13 @@ static int parse_env_file_internal( + if (value) + value[n_value] = 0; + +- /* Chomp off trailing whitespace */ +- if (last_whitespace != (size_t) -1) +- value[last_whitespace] = 0; ++ /* Chomp off trailing whitespace from value */ ++ if (last_value_whitespace != (size_t) -1) ++ value[last_value_whitespace] = 0; + + /* strip trailing whitespace from key */ +- while(n_key && strchr(WHITESPACE, key[--n_key])) +- key[n_key]=0; ++ if (last_key_whitespace != (size_t) -1) ++ key[last_key_whitespace] = 0; + + r = push(key, value, userdata); + if (r < 0) +@@ -300,14 +309,15 @@ static int parse_env_file_internal( + n_key = 0; + value = NULL; + value_alloc = n_value = 0; ++ + } else if (c == '\\') { + state = VALUE_ESCAPE; +- last_whitespace = (size_t) -1; ++ last_value_whitespace = (size_t) -1; + } else { + if (!strchr(WHITESPACE, c)) +- last_whitespace = (size_t) -1; +- else if (last_whitespace == (size_t) -1) +- last_whitespace = n_value; ++ last_value_whitespace = (size_t) -1; ++ else if (last_value_whitespace == (size_t) -1) ++ last_value_whitespace = n_value; + + if (!greedy_realloc((void**) &value, &value_alloc, n_value+2)) { + r = -ENOMEM; +@@ -417,9 +427,13 @@ static int parse_env_file_internal( + if (value) + value[n_value] = 0; + ++ if (state == VALUE) ++ if (last_value_whitespace != (size_t) -1) ++ value[last_value_whitespace] = 0; ++ + /* strip trailing whitespace from key */ +- while(n_key && strchr(WHITESPACE, key[--n_key])) +- key[n_key]=0; ++ if (last_key_whitespace != (size_t) -1) ++ key[last_key_whitespace] = 0; + + r = push(key, value, userdata); + if (r < 0) diff --git a/0058-core-execute-only-clean-the-environment-if-we-have-o.patch b/0058-core-execute-only-clean-the-environment-if-we-have-o.patch new file mode 100644 index 0000000..37ddc5d --- /dev/null +++ b/0058-core-execute-only-clean-the-environment-if-we-have-o.patch @@ -0,0 +1,24 @@ +From 341923eda80fc43cfcb2de76759b239c75c42ebf Mon Sep 17 00:00:00 2001 +From: Harald Hoyer +Date: Thu, 18 Apr 2013 07:15:03 +0200 +Subject: [PATCH] core/execute: only clean the environment, if we have one + (cherry picked from commit 5521d6985648669a65d0529bb01c7a32edc99294) + +--- + src/core/execute.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/core/execute.c b/src/core/execute.c +index 4b29d8e..11993df 100644 +--- a/src/core/execute.c ++++ b/src/core/execute.c +@@ -1757,7 +1757,8 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { + return k; + } + /* Log invalid environment variables with filename */ +- p = strv_env_clean_log(p, pglob.gl_pathv[n]); ++ if (p) ++ p = strv_env_clean_log(p, pglob.gl_pathv[n]); + + if (r == NULL) + r = p; diff --git a/systemd.spec b/systemd.spec index d130a7c..8b05414 100644 --- a/systemd.spec +++ b/systemd.spec @@ -13,7 +13,7 @@ Name: systemd Url: http://www.freedesktop.org/wiki/Software/systemd Version: 201 -Release: 2%{?gitcommit:.git%{gitcommit}}%{?dist}.6 +Release: 2%{?gitcommit:.git%{gitcommit}}%{?dist}.7 # For a breakdown of the licensing, see README License: LGPLv2+ and MIT and GPLv2+ Summary: A System and Service Manager @@ -93,6 +93,12 @@ Patch0049: 0049-man-clarify-behaviour-of-Also-in-unit-files.patch Patch0050: 0050-man-fix-typos-in-systemd.special.patch Patch0051: 0051-core-escape-unit-name-from-udev.patch Patch0052: 0052-journald-be-more-careful-when-we-try-to-flush-the-ru.patch +Patch0053: 0053-fileio-also-escape-and-when-writing-out-env-vars.patch +Patch0054: 0054-fileio-parse_env_file_internal-fix-environment-file-.patch +Patch0055: 0055-core-execute-report-invalid-environment-variables-fr.patch +Patch0056: 0056-fileio.c-do-not-parse-comments-after-non-whitespace-.patch +Patch0057: 0057-fileio-unify-how-we-chop-off-whitespace-from-key-and.patch +Patch0058: 0058-core-execute-only-clean-the-environment-if-we-have-o.patch # kernel-install patch for grubby, drop if grubby is obsolete Patch1000: kernel-install-grubby.patch @@ -830,6 +836,10 @@ fi %{_libdir}/pkgconfig/gudev-1.0* %changelog +* Fri May 17 2013 Michal Schmidt - 201-2.fc18.7 +- Pick fileio fixes for environment files (#964132). +- Drop isdn.service from default preset (Lennart, #959793). + * Tue May 07 2013 Michal Schmidt - 201-2.fc18.6 - Avoid sysctl.d precedence rules change (#924433). - More patches from upstream.