All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation
@ 2020-11-18  6:58 Tianjia Zhang
  2021-03-14 11:09 ` Tianjia Zhang
  2021-05-26  8:38 ` Tianjia Zhang
  0 siblings, 2 replies; 6+ messages in thread
From: Tianjia Zhang @ 2020-11-18  6:58 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel; +Cc: Tianjia Zhang

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));
-- 
2.24.3 (Apple Git-128)



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation
  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
  2021-05-26  8:38 ` Tianjia Zhang
  1 sibling, 1 reply; 6+ messages in thread
From: Tianjia Zhang @ 2021-03-14 11:09 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel

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));
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation
  2021-03-14 11:09 ` Tianjia Zhang
@ 2021-03-15  1:26   ` Glenn Washburn
  2021-05-26  8:37     ` Tianjia Zhang
  0 siblings, 1 reply; 6+ messages in thread
From: Glenn Washburn @ 2021-03-15  1:26 UTC (permalink / raw)
  To: Tianjia Zhang; +Cc: The development of GNU GRUB, Daniel Kiper

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation
  2021-03-15  1:26   ` Glenn Washburn
@ 2021-05-26  8:37     ` Tianjia Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Tianjia Zhang @ 2021-05-26  8:37 UTC (permalink / raw)
  To: The development of GNU GRUB, Glenn Washburn, Daniel Kiper; +Cc: Daniel Kiper



On 3/15/21 9:26 AM, Glenn Washburn wrote:
> 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
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 


Thanks for your review.

Best regards,
Tianjia


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation
  2020-11-18  6:58 [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation Tianjia Zhang
  2021-03-14 11:09 ` Tianjia Zhang
@ 2021-05-26  8:38 ` Tianjia Zhang
  2021-05-26 14:46   ` Daniel Kiper
  1 sibling, 1 reply; 6+ messages in thread
From: Tianjia Zhang @ 2021-05-26  8:38 UTC (permalink / raw)
  To: Daniel Kiper, grub-devel

Hi Daniel,

Please take the time to look at this patch.

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));
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation
  2021-05-26  8:38 ` Tianjia Zhang
@ 2021-05-26 14:46   ` Daniel Kiper
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Kiper @ 2021-05-26 14:46 UTC (permalink / raw)
  To: Tianjia Zhang; +Cc: grub-devel

Hi Tianjia,

On Wed, May 26, 2021 at 04:38:33PM +0800, Tianjia Zhang wrote:
> Hi Daniel,
>
> Please take the time to look at this patch.

Thank you for the patch. I do not consider it as release material.
So, I will take a look at this patch after release.

Daniel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-26 14:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-05-26  8:37     ` Tianjia Zhang
2021-05-26  8:38 ` Tianjia Zhang
2021-05-26 14:46   ` Daniel Kiper

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.