diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-24 14:55:57 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-25 13:36:34 +0200 |
commit | 7bb553bb98a57b4e03804f8192bdc5a534325582 (patch) | |
tree | 3040cd663b06af6e92f57ef8b1100956469a9f40 /src/shared/fstab-util.c | |
parent | core/execute: escape the separator in exported paths (diff) | |
download | systemd-7bb553bb98a57b4e03804f8192bdc5a534325582.tar.xz systemd-7bb553bb98a57b4e03804f8192bdc5a534325582.zip |
fstab,crypttab: allow escaping of commas
Fixes #17035. We use "," as the separator between arguments in fstab and crypttab
options field, but the kernel started using "," within arguments. Users will need
to escape those nested commas.
Diffstat (limited to 'src/shared/fstab-util.c')
-rw-r--r-- | src/shared/fstab-util.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index d883eca5c7..ca88813602 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -95,7 +95,19 @@ int fstab_filter_options(const char *opts, const char *names, if (!ret_filtered) { for (const char *word = opts;;) { - const char *end = word + strcspn(word, ","); + const char *end = word; + + /* Look for an *non-escaped* comma separator. Only commas can be escaped, so "\," is + * the only valid escape sequence, so we can do a very simple test here. */ + for (;;) { + size_t n = strcspn(end, ","); + + end += n; + if (n > 0 && end[-1] == '\\') + end++; + else + break; + } NULSTR_FOREACH(name, names) { if (end < word + strlen(name)) @@ -128,9 +140,10 @@ int fstab_filter_options(const char *opts, const char *names, break; } } else { - stor = strv_split(opts, ","); - if (!stor) - return -ENOMEM; + r = strv_split_full(&stor, opts, ",", EXTRACT_DONT_COALESCE_SEPARATORS | EXTRACT_UNESCAPE_SEPARATORS); + if (r < 0) + return r; + strv = memdup(stor, sizeof(char*) * (strv_length(stor) + 1)); if (!strv) return -ENOMEM; @@ -165,7 +178,7 @@ answer: if (ret_filtered) { char *f; - f = strv_join(strv, ","); + f = strv_join_full(strv, ",", NULL, true); if (!f) return -ENOMEM; |