From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1llp4C-000790-OZ for mharc-grub-devel@gnu.org; Wed, 26 May 2021 04:39:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llp4B-00076V-7t for grub-devel@gnu.org; Wed, 26 May 2021 04:39:03 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:30491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llp49-0000Ib-Az for grub-devel@gnu.org; Wed, 26 May 2021 04:39:02 -0400 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R161e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04395; MF=tianjia.zhang@linux.alibaba.com; NM=1; PH=DS; RN=2; SR=0; TI=SMTPD_---0Ua9lYvD_1622018313; Received: from B-455UMD6M-2027.local(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0Ua9lYvD_1622018313) by smtp.aliyun-inc.com(127.0.0.1); Wed, 26 May 2021 16:38:33 +0800 Subject: Re: [PATCH] grub-mkpasswd-pbkdf2: Simplify the main function implementation To: Daniel Kiper , grub-devel@gnu.org References: <20201118065842.32049-1-tianjia.zhang@linux.alibaba.com> From: Tianjia Zhang Message-ID: Date: Wed, 26 May 2021 16:38:33 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20201118065842.32049-1-tianjia.zhang@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=47.88.44.36; envelope-from=tianjia.zhang@linux.alibaba.com; helo=out4436.biz.mail.alibaba.com X-Spam_score_int: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, ENV_AND_HDR_SPF_MATCH=-0.5, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 May 2021 08:39:03 -0000 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 > --- > 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)); >