]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup: port to strprepend()
authorMike Yuan <me@yhndnzj.com>
Mon, 10 Feb 2025 18:04:08 +0000 (19:04 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 10 Feb 2025 18:39:21 +0000 (19:39 +0100)
src/cryptsetup/cryptsetup.c

index 6fd10613d14c1bdf9b9933c8a54b4ef3046cc396..d109d0914ffd27d25867ac855b06180ca2402270 100644 (file)
@@ -600,14 +600,15 @@ static int parse_one_option(const char *option) {
                  * - text descriptions prefixed with "%:" or "%keyring:".
                  * - text description with no prefix.
                  * - numeric keyring id (ignored in current patch set). */
-                if (IN_SET(*val, '@', '%'))
-                        keyring = strndup(val, sep - val);
-                else
-                        /* add type prefix if missing (crypt_set_keyring_to_link() expects it) */
-                        keyring = strnappend("%:", val, sep - val);
+                keyring = strndup(val, sep - val);
                 if (!keyring)
                         return log_oom();
 
+                /* add type prefix if missing (crypt_set_keyring_to_link() expects it) */
+                if (!IN_SET(*keyring, '@', '%'))
+                        if (!strprepend(&keyring, "%:"))
+                                return log_oom();
+
                 sep += 2;
 
                 /* %<key_type> is optional (and defaults to 'user') */