All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org, Daniel Kiper <daniel.kiper@oracle.com>
Cc: Glenn Washburn <development@efficientek.com>
Subject: [PATCH 4/4] luks2: Fix potential grub_free with NULL pointer
Date: Fri, 19 Mar 2021 19:14:51 -0500	[thread overview]
Message-ID: <bd9831f396f60fff2a4b49a6ceda411278d600c2.1616198999.git.development@efficientek.com> (raw)
In-Reply-To: <cover.1616198999.git.development@efficientek.com>

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



  parent reply	other threads:[~2021-03-20  0:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-20  0:14 [PATCH 0/4] Various LUKS2 improvements Glenn Washburn
2021-03-20  0:14 ` [PATCH 1/4] luks2: Continue trying all keyslots even if there are some failures Glenn Washburn
2021-03-20  0:14 ` [PATCH 2/4] luks2: Add error message strings to crypto errors Glenn Washburn
2021-03-20  0:14 ` [PATCH 3/4] luks2: Add error message strings to errors in luks2_read_header Glenn Washburn
2021-03-20  0:14 ` Glenn Washburn [this message]
2021-03-23 17:43 ` [PATCH 0/4] Various LUKS2 improvements Daniel Kiper
2021-03-23 19:41   ` Daniel Kiper
2021-03-24  4:01   ` Glenn Washburn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bd9831f396f60fff2a4b49a6ceda411278d600c2.1616198999.git.development@efficientek.com \
    --to=development@efficientek.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.