From 1c6d66fccc91ff37d7f991a3213bc33f5f6426b6 Mon Sep 17 00:00:00 2001
From: Ondrej Kozina <okozina@redhat.com>
Date: Fri, 14 Sep 2018 11:18:48 +0200
Subject: [PATCH 040/324] Emit error message for converting inactive keyslot.

Fixes: #416.
---
 src/cryptsetup.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/cryptsetup.c b/src/cryptsetup.c
index 52efd71..cc3520c 100644
--- a/src/cryptsetup.c
+++ b/src/cryptsetup.c
@@ -1535,6 +1535,12 @@ static int action_luksConvertKey(void)
 	if ((r = crypt_load(cd, CRYPT_LUKS2, NULL)))
 		goto out;
 
+	if (crypt_keyslot_status(cd, opt_key_slot) == CRYPT_SLOT_INACTIVE) {
+		r = -EINVAL;
+		log_err(_("Keyslot %d is not active."), opt_key_slot);
+		goto out;
+	}
+
 	r = set_pbkdf_params(cd, crypt_get_type(cd));
 	if (r) {
 		log_err(_("Failed to set pbkdf parameters."));
-- 
2.19.1

