]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: unescape ID_PART_ENTRY_NAME udev property before using it 18734/head
authorLennart Poettering <lennart@poettering.net>
Mon, 22 Feb 2021 16:38:02 +0000 (17:38 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 22 Feb 2021 16:39:50 +0000 (17:39 +0100)
Fixes: #18729
src/cryptsetup/cryptsetup.c

index ebfef02aee210084be0ac3e20b0b7a334c65b735..65e328389dcfb4ef20bf6bb5daabf844f45cf519 100644 (file)
@@ -419,7 +419,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";
@@ -427,6 +426,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);
 
@@ -439,6 +439,24 @@ static char* disk_description(const char *path) {
         if (sd_device_new_from_stat_rdev(&device, &st) < 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))