From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lLOdV-00083J-Bq for mharc-grub-devel@gnu.org; Sun, 14 Mar 2021 07:10:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLOdQ-00082y-Mm for grub-devel@gnu.org; Sun, 14 Mar 2021 07:10:13 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:49555) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLOdI-0006gk-9O for grub-devel@gnu.org; Sun, 14 Mar 2021 07:10:07 -0400 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R851e4; 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_---0URqiRCw_1615720177; Received: from 30.25.246.105(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0URqiRCw_1615720177) by smtp.aliyun-inc.com(127.0.0.1); Sun, 14 Mar 2021 19:09:38 +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: <48c2f315-c124-123f-4350-16e6e068e545@linux.alibaba.com> Date: Sun, 14 Mar 2021 19:09:36 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.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: Sun, 14 Mar 2021 11:10:13 -0000 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 > --- > 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)); >