public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
From: Ken Goldman <kgold@linux.ibm.com>
To: Mimi Zohar <zohar@linux.ibm.com>, Bruno Meneguele <bmeneg@redhat.com>
Cc: vt@altlinux.org, linux-integrity@vger.kernel.org
Subject: Re: [PATCH ima-evm-utils] evmctl: fix memory leak in get_password
Date: Wed, 11 Aug 2021 14:28:37 -0400	[thread overview]
Message-ID: <b8d5fdd1-ffc0-4db4-4993-a31da2c3140c@linux.ibm.com> (raw)
In-Reply-To: <1e261f41462aac5e9fbb6d9397f5f86a5379a803.camel@linux.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 1143 bytes --]

On 8/11/2021 1:31 PM, Mimi Zohar wrote:
> On Wed, 2021-08-11 at 13:51 -0300, Bruno Meneguele wrote:
>> On Wed, Aug 11, 2021 at 10:52:00AM -0400, Mimi Zohar wrote:
>>
>>>>
>>>> -	return pwd;
>>>> +	return password;
>>>
>>> Wouldn't a simpler fix be to test "pwd" here?
>>>          if (!pwd)
>>>                  free(password);
>>>          return pwd;
>>>
>>
>> The problem is on success, when 'pwd' is actually not NULL.
>> With that, I can't free(password). I would need to asprintf(pwd, ...) or
>> strndup(password). Because of that, I thought it would be cleaner to
>> remove 'password' completely.
> 
> I see.  So instead of "return pwd" as suggested above,
> 
>          if (!pwd) {
>                  free(password);
>                  password = NULL;  <== set or return NULL
>          }
> 
>          return password;

That looks cleaner to me.

My style would be

	if (pwd == NULL)

which compiles to the same binary, but it less prone to error.

In addition, since this is reading from stdin

1 - Do you want the newline to be part of the password?
2 = Why is an empty password an error?


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4490 bytes --]

  parent reply	other threads:[~2021-08-11 18:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 20:28 [PATCH ima-evm-utils] evmctl: fix memory leak in get_password Bruno Meneguele
2021-08-11 14:52 ` Mimi Zohar
2021-08-11 16:51   ` Bruno Meneguele
2021-08-11 17:31     ` Mimi Zohar
2021-08-11 17:52       ` Bruno Meneguele
2021-08-11 18:28       ` Ken Goldman [this message]
2021-08-16 15:10         ` Bruno Meneguele

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=b8d5fdd1-ffc0-4db4-4993-a31da2c3140c@linux.ibm.com \
    --to=kgold@linux.ibm.com \
    --cc=bmeneg@redhat.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=vt@altlinux.org \
    --cc=zohar@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox