diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-02-22 17:38:02 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-03-12 18:20:46 +0100 |
commit | ffd185fa0530de2c147e34b646f767cdfcfa4495 (patch) | |
tree | 0fdaf9af579a91a130d3ee3a2c07c6e8a5d317e0 | |
parent | d8a0ecb6e9ae33b4c1c20bca4f5f2548aed2038d (diff) | |
download | systemd-ffd185fa0530de2c147e34b646f767cdfcfa4495.tar.gz |
cryptsetup: unescape ID_PART_ENTRY_NAME udev property before using it
Fixes: #18729
(cherry picked from commit fadd34dd5af9a26edf2906b237ac212169d39f0c)
(cherry picked from commit 01459676644e7d358176963d58a6f8022eaf1ff5)
-rw-r--r-- | src/cryptsetup/cryptsetup.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 12e32ebf05..458b6efc72 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -324,7 +324,6 @@ static int parse_options(const char *options) { static char* disk_description(const char *path) { static const char name_fields[] = - "ID_PART_ENTRY_NAME\0" "DM_NAME\0" "ID_MODEL_FROM_DATABASE\0" "ID_MODEL\0"; @@ -332,6 +331,7 @@ static char* disk_description(const char *path) { _cleanup_(sd_device_unrefp) sd_device *device = NULL; const char *i, *name; struct stat st; + int r; assert(path); @@ -344,6 +344,24 @@ static char* disk_description(const char *path) { if (sd_device_new_from_devnum(&device, 'b', st.st_rdev) < 0) return NULL; + if (sd_device_get_property_value(device, "ID_PART_ENTRY_NAME", &name) >= 0) { + _cleanup_free_ char *unescaped = NULL; + + /* ID_PART_ENTRY_NAME uses \x style escaping, using libblkid's blkid_encode_string(). Let's + * reverse this here to make the string more human friendly in case people embed spaces or + * other weird stuff. */ + + r = cunescape(name, UNESCAPE_RELAX, &unescaped); + if (r < 0) { + log_debug_errno(r, "Failed to unescape ID_PART_ENTRY_NAME, skipping device: %m"); + return NULL; + } + + if (!isempty(unescaped) && !string_has_cc(unescaped, NULL)) + return TAKE_PTR(unescaped); + } + + /* These need no unescaping. */ NULSTR_FOREACH(i, name_fields) if (sd_device_get_property_value(device, i, &name) >= 0 && !isempty(name)) |