]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
util/grub-mkpasswd-pbkdf2: Simplify the main function implementation
authorTianjia Zhang <tianjia.zhang@linux.alibaba.com>
Mon, 27 May 2024 12:42:04 +0000 (20:42 +0800)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 6 Jun 2024 14:55:16 +0000 (16:55 +0200)
Allocate memory if needed, while saving the corresponding release
operation, reducing the amount of code and code complexity.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/grub-mkpasswd-pbkdf2.c

index 29c68fbf58e22301d1e4220e3527c459f3e33b07..51e7065100a60f199f86be32293f617620a5bb1d 100644 (file)
@@ -133,34 +133,24 @@ main (int argc, char *argv[])
       exit(1);
     }
 
-  buf = xmalloc (arguments.buflen);
-  salt = xmalloc (arguments.saltlen);
-
   printf ("%s", _("Enter password: "));
   if (!grub_password_get (pass1, GRUB_AUTH_MAX_PASSLEN))
-    {
-      free (buf);
-      free (salt);
-      grub_util_error ("%s", _("failure to read password"));
-    }
+    grub_util_error ("%s", _("failure to read password"));
   printf ("%s", _("Reenter password: "));
   if (!grub_password_get (pass2, GRUB_AUTH_MAX_PASSLEN))
-    {
-      free (buf);
-      free (salt);
-      grub_util_error ("%s", _("failure to read password"));
-    }
+    grub_util_error ("%s", _("failure to read password"));
 
   if (strcmp (pass1, pass2) != 0)
     {
       memset (pass1, 0, sizeof (pass1));
       memset (pass2, 0, sizeof (pass2));
-      free (buf);
-      free (salt);
       grub_util_error ("%s", _("passwords don't match"));
     }
   memset (pass2, 0, sizeof (pass2));
 
+  buf = xmalloc (arguments.buflen);
+  salt = xmalloc (arguments.saltlen);
+
   if (grub_get_random (salt, arguments.saltlen))
     {
       memset (pass1, 0, sizeof (pass1));