All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Cc: The development of GNU GRUB <grub-devel@gnu.org>,
	Daniel Kiper <daniel.kiper@oracle.com>
Subject: Re: [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation
Date: Sun, 14 Mar 2021 20:26:48 -0500	[thread overview]
Message-ID: <20210314202648.167be00f@crass-HP-ZBook-15-G2> (raw)
In-Reply-To: <48c2f315-c124-123f-4350-16e6e068e545@linux.alibaba.com>

On Sun, 14 Mar 2021 19:09:36 +0800
Tianjia Zhang <tianjia.zhang@linux.alibaba.com> wrote:

> ping.
> 
> Thanks,
> Tianjia
> 
> On 11/18/20 2:58 PM, Tianjia Zhang wrote:
> > 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>
> > ---
> >   util/grub-mkpasswd-pbkdf2.c | 20 +++++---------------
> >   1 file changed, 5 insertions(+), 15 deletions(-)
> > 
> > diff --git a/util/grub-mkpasswd-pbkdf2.c
> > b/util/grub-mkpasswd-pbkdf2.c index 5805f3c10..cd7943df6 100644
> > --- a/util/grub-mkpasswd-pbkdf2.c
> > +++ b/util/grub-mkpasswd-pbkdf2.c
> > @@ -132,35 +132,25 @@ main (int argc, char *argv[])
> >         fprintf (stderr, "%s", _("Error in parsing command line
> > arguments\n")); 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));
> > 

LGTM. I wonder if there's some conventions as with local variable
declaration, where we try to have memory allocation near the beginning
of the function as a kind of "declaration" that this should be freed
before leaving the function.

  Reviewed-by: Glenn Washburn <development@efficientek.com>

Glenn


  reply	other threads:[~2021-03-15  1:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18  6:58 [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation Tianjia Zhang
2021-03-14 11:09 ` Tianjia Zhang
2021-03-15  1:26   ` Glenn Washburn [this message]
2021-05-26  8:37     ` Tianjia Zhang
2021-05-26  8:38 ` Tianjia Zhang
2021-05-26 14:46   ` Daniel Kiper
2024-05-27 12:29 Tianjia Zhang
2024-05-27 12:42 Tianjia Zhang

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=20210314202648.167be00f@crass-HP-ZBook-15-G2 \
    --to=development@efficientek.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=tianjia.zhang@linux.alibaba.com \
    /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.