From 01a2025d052f4a762d538f6b23c06924042ade3b Mon Sep 17 00:00:00 2001
From: Arie Peterson <arie@greenhost.nl>
Date: Thu, 20 Jul 2017 14:37:37 +0200
Subject: [PATCH] Deal with failure of crypt_keyslot_max

---
 src/api/encryption_keys_get.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/api/encryption_keys_get.c b/src/api/encryption_keys_get.c
index ec13c32..6a2ce35 100644
--- a/src/api/encryption_keys_get.c
+++ b/src/api/encryption_keys_get.c
@@ -34,7 +34,14 @@ int callback_encryption_keys_get(const struct _u_request * request,
     bool in_use;
     bool last_used;
     int keyslot = 0;
-    for (keyslot = 0; keyslot <= crypt_keyslot_max(CRYPT_LUKS1); keyslot++)
+    int keyslot_max = crypt_keyslot_max(CRYPT_LUKS1);
+    if (keyslot_max < 0)
+    {
+        return send_simple_response(response, 500, "error",
+            "crypt_keyslot_max failed");
+    }
+
+    for (keyslot = 0; keyslot < keyslot_max; keyslot++)
     {
         // Create new json object containing info for this keyslot.
         key = json_object();
-- 
GitLab