diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-17 11:13:20 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-17 11:35:04 +0200 |
commit | 8a07b4033e5d3c86931b3dd2ddbca41118c05c60 (patch) | |
tree | b7a3941d5ba8c28ff256464b7e01f3de935b5691 /src | |
parent | fa8b675ae0c341daa141cce8783c106e048045e1 (diff) | |
download | systemd-8a07b4033e5d3c86931b3dd2ddbca41118c05c60.tar.gz systemd-8a07b4033e5d3c86931b3dd2ddbca41118c05c60.tar.bz2 systemd-8a07b4033e5d3c86931b3dd2ddbca41118c05c60.zip |
shared/conf-parser,networkd: EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE → EXTRACT_UNQUOTE
It's hard to even say what exactly this combination means. Escaping is
necessary when quoting to have quotes within the string. So the escaping of
quote characters is inherently tied to quoting. When unquoting, it seems
natural to remove escaping which was done for the quoting purposes. But with
both flags we would be expected to re-add this escaping after unqouting? Or
maybe keep the escaping which is not necessary for quoting but otherwise
present? This all seems too complicated, let's just forbid such usage and
always fully unescape when unquoting.
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/extract-word.c | 2 | ||||
-rw-r--r-- | src/libsystemd-network/network-internal.c | 2 | ||||
-rw-r--r-- | src/shared/conf-parser.c | 2 | ||||
-rw-r--r-- | src/test/test-extract-word.c | 24 |
4 files changed, 28 insertions, 2 deletions
diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index 34cfb36a4a..b7ae2ed1cd 100644 --- a/src/basic/extract-word.c +++ b/src/basic/extract-word.c @@ -28,6 +28,8 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra assert(p); assert(ret); + /* Those two don't make sense together. */ + assert(!FLAGS_SET(flags, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE)); /* Bail early if called after last value or with no input */ if (!*p) diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index 1f2e5c7e65..f18ec88300 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -254,7 +254,7 @@ int config_parse_match_strv( for (;;) { _cleanup_free_ char *word = NULL, *k = NULL; - r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); + r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE); if (r == 0) return 0; if (r == -ENOMEM) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index c27c499eda..62fc1c97b7 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -758,7 +758,7 @@ int config_parse_strv( for (;;) { char *word = NULL; - r = extract_first_word(&rvalue, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); + r = extract_first_word(&rvalue, &word, NULL, EXTRACT_UNQUOTE); if (r == 0) break; if (r == -ENOMEM) diff --git a/src/test/test-extract-word.c b/src/test/test-extract-word.c index f148b3e6f1..bf47a598a9 100644 --- a/src/test/test-extract-word.c +++ b/src/test/test-extract-word.c @@ -83,6 +83,30 @@ static void test_extract_first_word(void) { free(t); assert_se(isempty(p)); + p = original = "KEY=val \"KEY2=val with space\" \"KEY3=val with \\\"quotation\\\"\""; + assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1); + assert_se(streq(t, "KEY=val")); + free(t); + assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1); + assert_se(streq(t, "KEY2=val with space")); + free(t); + assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == 1); + assert_se(streq(t, "KEY3=val with \"quotation\"")); + free(t); + assert_se(isempty(p)); + + p = original = "KEY=val \"KEY2=val space\" \"KEY3=val with \\\"quotation\\\"\""; + assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1); + assert_se(streq(t, "KEY=val")); + free(t); + assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1); + assert_se(streq(t, "\"KEY2=val")); + free(t); + assert_se(extract_first_word(&p, &t, NULL, EXTRACT_RETAIN_ESCAPE) == 1); + assert_se(streq(t, "space\"")); + free(t); + assert_se(startswith(p, "\"KEY3=")); + p = original = "\'fooo"; assert_se(extract_first_word(&p, &t, NULL, EXTRACT_UNQUOTE) == -EINVAL); assert_se(p == original + 5); |