anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0663-cryptsetup-generator-allow-whitespace-characters-in-.patch

a9339c
From afcf3919f5db85a00352a9937c9a5cb9c7b30269 Mon Sep 17 00:00:00 2001
a9339c
From: Michal Sekletar <msekleta@redhat.com>
a9339c
Date: Tue, 4 Sep 2018 20:03:34 +0200
a9339c
Subject: [PATCH] cryptsetup-generator: allow whitespace characters in keydev
a9339c
 specification
a9339c
a9339c
For example, <luks.uuid>=/keyfile:LABEL="KEYFILE FS" previously wouldn't
a9339c
work, because we truncated label at the first whitespace character,
a9339c
i.e. LABEL="KEYFILE".
a9339c
a9339c
Related: #1619743
a9339c
---
a9339c
 src/cryptsetup/cryptsetup-generator.c | 21 +++++++++++++++------
a9339c
 1 file changed, 15 insertions(+), 6 deletions(-)
a9339c
a9339c
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
a9339c
index a9598180c..7b90d2615 100644
a9339c
--- a/src/cryptsetup/cryptsetup-generator.c
a9339c
+++ b/src/cryptsetup/cryptsetup-generator.c
a9339c
@@ -421,27 +421,36 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
a9339c
                         return log_oom();
a9339c
 
a9339c
         } else if (STR_IN_SET(key, "luks.key", "rd.luks.key") && value) {
a9339c
+                int n;
a9339c
 
a9339c
-                r = sscanf(value, "%m[0-9a-fA-F-]=%ms", &uuid, &uuid_value);
a9339c
-                if (r == 2) {
a9339c
+                r = sscanf(value, "%m[0-9a-fA-F-]=%n", &uuid, &n);
a9339c
+                if (r == 1) {
a9339c
                         char *c;
a9339c
+                        const char *keyspec;
a9339c
                         _cleanup_free_ char *keyfile = NULL, *keydev = NULL;
a9339c
 
a9339c
                         d = get_crypto_device(uuid);
a9339c
                         if (!d)
a9339c
                                 return log_oom();
a9339c
 
a9339c
-                        c = strrchr(uuid_value, ':');
a9339c
+                        keyspec = value + n;
a9339c
+
a9339c
+                        c = strrchr(keyspec, ':');
a9339c
                         if (!c) {
a9339c
+                                /* No keydev specified */
a9339c
+                                keyfile = strdup(keyspec);
a9339c
+                                if (!keyfile)
a9339c
+                                        return log_oom();
a9339c
+
a9339c
                                 free(d->keyfile);
a9339c
-                                d->keyfile = uuid_value;
a9339c
-                                uuid_value = NULL;
a9339c
+                                d->keyfile = keyfile;
a9339c
+                                keyfile = NULL;
a9339c
 
a9339c
                                 return 0;
a9339c
                         }
a9339c
 
a9339c
                         *c = '\0';
a9339c
-                        keyfile = strdup(uuid_value);
a9339c
+                        keyfile = strdup(keyspec);
a9339c
                         keydev = strdup(++c);
a9339c
 
a9339c
                         if (!keyfile || !keydev)