daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
c2dfb7
From 5cdb2b0b2a0f8f89f97053b0633b8419506d4e28 Mon Sep 17 00:00:00 2001
c2dfb7
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
c2dfb7
Date: Thu, 1 Aug 2019 08:15:43 +0200
c2dfb7
Subject: [PATCH] cryptsetup: don't assert on variable which is optional
c2dfb7
c2dfb7
https://github.com/systemd/systemd/commit/50d2eba27b9bfc77ef6b40e5721713846815418b#commitcomment-34519739
c2dfb7
c2dfb7
In add_crypttab_devices() split_keyspec is called on the keyfile argument,
c2dfb7
which may be NULL.
c2dfb7
c2dfb7
(cherry picked from commit fef716b28be6e866b8afe995805d5ebe2af6bbfa)
c2dfb7
c2dfb7
Related: #1763155
c2dfb7
---
c2dfb7
 src/cryptsetup/cryptsetup-generator.c | 6 +++++-
c2dfb7
 1 file changed, 5 insertions(+), 1 deletion(-)
c2dfb7
c2dfb7
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
c2dfb7
index 7b234e37be..a09983b576 100644
c2dfb7
--- a/src/cryptsetup/cryptsetup-generator.c
c2dfb7
+++ b/src/cryptsetup/cryptsetup-generator.c
c2dfb7
@@ -44,10 +44,14 @@ static int split_keyspec(const char *keyspec, char **ret_keyfile, char **ret_key
c2dfb7
         _cleanup_free_ char *keyfile = NULL, *keydev = NULL;
c2dfb7
         const char *c;
c2dfb7
 
c2dfb7
-        assert(keyspec);
c2dfb7
         assert(ret_keyfile);
c2dfb7
         assert(ret_keydev);
c2dfb7
 
c2dfb7
+        if (!keyspec) {
c2dfb7
+                *ret_keyfile = *ret_keydev = NULL;
c2dfb7
+                return 0;
c2dfb7
+        }
c2dfb7
+
c2dfb7
         c = strrchr(keyspec, ':');
c2dfb7
         if (c) {
c2dfb7
                 keyfile = strndup(keyspec, c-keyspec);