grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/4] luks2: Fix potential grub_free with NULL pointer


From: Glenn Washburn
Subject: [PATCH 4/4] luks2: Fix potential grub_free with NULL pointer
Date: Fri, 19 Mar 2021 19:14:51 -0500

This is not strictly necessary because grub_free does nothing if it is
passed a NULL pointer. However, it simplifies the code and makes it a tad
bit easier to read.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/disk/luks2.c | 34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
index 2ed9e5a80..0e86325c7 100644
--- a/grub-core/disk/luks2.c
+++ b/grub-core/disk/luks2.c
@@ -437,25 +437,18 @@ luks2_decrypt_key (grub_uint8_t *out_key,
 
   if (!base64_decode (k->kdf.salt, grub_strlen (k->kdf.salt),
                     (char *)salt, &saltlen))
-    {
-      ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid keyslot salt");
-      goto err;
-    }
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid keyslot salt");
 
   /* Calculate the binary area key of the user supplied passphrase. */
   switch (k->kdf.type)
     {
       case LUKS2_KDF_TYPE_ARGON2I:
-       ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported");
-       goto err;
+       return grub_error (GRUB_ERR_BAD_ARGUMENT, "Argon2 not supported");
       case LUKS2_KDF_TYPE_PBKDF2:
        hash = grub_crypto_lookup_md_by_name (k->kdf.u.pbkdf2.hash);
        if (!hash)
-         {
-           ret = grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash",
-                             k->kdf.u.pbkdf2.hash);
-           goto err;
-         }
+         return grub_error (GRUB_ERR_FILE_NOT_FOUND, "Couldn't load %s hash",
+                           k->kdf.u.pbkdf2.hash);
 
        gcry_ret = grub_crypto_pbkdf2 (hash, (grub_uint8_t *) passphrase,
                                       passphraselen,
@@ -463,11 +456,8 @@ luks2_decrypt_key (grub_uint8_t *out_key,
                                       k->kdf.u.pbkdf2.iterations,
                                       area_key, k->area.key_size);
        if (gcry_ret)
-         {
-           ret = grub_error (grub_crypto_gcry_error (gcry_ret),
-                             "grub_crypto_pbkdf2 failed with code %d", 
gcry_ret);
-           goto err;
-         }
+         return grub_error (grub_crypto_gcry_error (gcry_ret),
+                            "grub_crypto_pbkdf2 failed with code %d", 
gcry_ret);
 
        break;
     }
@@ -485,19 +475,13 @@ luks2_decrypt_key (grub_uint8_t *out_key,
 
   gcry_ret = grub_cryptodisk_setkey (crypt, area_key, k->area.key_size);
   if (gcry_ret)
-    {
-      ret = grub_error (grub_crypto_gcry_error (gcry_ret),
-                       "grub_cryptodisk_setkey failed with code %d", gcry_ret);
-      goto err;
-    }
+    return grub_error (grub_crypto_gcry_error (gcry_ret),
+                      "grub_cryptodisk_setkey failed with code %d", gcry_ret);
 
  /* Read and decrypt the binary key area with the area key. */
   split_key = grub_malloc (k->area.size);
   if (!split_key)
-    {
-      ret = grub_errno;
-      goto err;
-    }
+    return grub_errno;
 
   grub_errno = GRUB_ERR_NONE;
   ret = grub_disk_read (source, 0, k->area.offset, k->area.size, split_key);
-- 
2.27.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]