diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-10-01 10:26:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 10:26:24 +0200 |
commit | fabf8777051aedf0b1cdfe1d28a4c80a7f3358a4 (patch) | |
tree | e8991216eaada8db3a338881a3bba145ee583632 /src/shared | |
parent | Merge pull request #17213 from keszybz/man-cleanups (diff) | |
parent | man: describe comma escaping in crypttab(5) (diff) | |
download | systemd-fabf8777051aedf0b1cdfe1d28a4c80a7f3358a4.tar.xz systemd-fabf8777051aedf0b1cdfe1d28a4c80a7f3358a4.zip |
Merge pull request #17154 from keszybz/crypttab-commas
Allow escaping commas in crypttab
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/fstab-util.c | 23 | ||||
-rw-r--r-- | src/shared/udev-util.c | 9 |
2 files changed, 23 insertions, 9 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; diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 31fbfac9cf..1b5995c130 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -118,12 +118,13 @@ static int device_new_from_dev_path(const char *devlink, sd_device **ret_device) assert(devlink); - r = stat(devlink, &st); - if (r < 0) - return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno, "Failed to stat() %s: %m", devlink); + if (stat(devlink, &st) < 0) + return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno, + "Failed to stat() %s: %m", devlink); if (!S_ISBLK(st.st_mode)) - return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), "%s does not point to a block device: %m", devlink); + return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), + "%s does not point to a block device: %m", devlink); r = sd_device_new_from_devnum(ret_device, 'b', st.st_rdev); if (r < 0) |