From: Carlos O'Donell <carlos@redhat.com>
To: Robbie Harwood <rharwood@redhat.com>,
libc-alpha@sourceware.org, fweimer@redhat.com
Subject: Re: [PATCH v2 1/1] nis: Fix leak on realloc failure in nis_getnames [BZ #28150]
Date: Mon, 2 Aug 2021 11:24:44 -0400 [thread overview]
Message-ID: <a9965b8b-116d-205d-bd55-5d728009b2a2@redhat.com> (raw)
In-Reply-To: <20210728182331.1363922-1-rharwood@redhat.com>
On 7/28/21 2:23 PM, Robbie Harwood via Libc-alpha wrote:
> If pos >= count but realloc fails, tmp will not have been placed in
> getnames[pos] yet, and so will not be freed in free_null. Detected
> by Coverity.
>
> Also remove misleading comment from nis_getnames(), since it actually
> did properly release getnames when out of memory.
The CI/CD patchwork trybot didn't trigger for this patch and I need
to review that with DJ.
I tested on x86_64 and i686 without regression. Florian reviewed.
I'm pushing this fix.
Tested-by: Carlos O'Donell <carlos@redhat.com>
> ---
> nis/nis_subr.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/nis/nis_subr.c b/nis/nis_subr.c
> index dd0e30071d..6784fc353f 100644
> --- a/nis/nis_subr.c
> +++ b/nis/nis_subr.c
> @@ -103,9 +103,6 @@ count_dots (const_nis_name str)
> return count;
> }
>
> -/* If we run out of memory, we don't give already allocated memory
> - free. The overhead for bringing getnames back in a safe state to
> - free it is to big. */
> nis_name *
> nis_getnames (const_nis_name name)
> {
> @@ -271,7 +268,10 @@ nis_getnames (const_nis_name name)
> nis_name *newp = realloc (getnames,
> (count + 1) * sizeof (char *));
> if (__glibc_unlikely (newp == NULL))
> - goto free_null;
> + {
> + free (tmp);
> + goto free_null;
> + }
> getnames = newp;
> }
> getnames[pos] = tmp;
>
--
Cheers,
Carlos.
next prev parent reply other threads:[~2021-08-02 15:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-28 17:47 [PATCH v1] nis: Fix leak on realloc failure in nis_getnames Robbie Harwood
2021-07-28 18:03 ` Florian Weimer
2021-07-28 18:23 ` [PATCH v2 1/1] nis: Fix leak on realloc failure in nis_getnames [BZ #28150] Robbie Harwood
2021-08-02 15:24 ` Carlos O'Donell [this message]
2021-07-28 18:06 ` [PATCH v1] nis: Fix leak on realloc failure in nis_getnames Robbie Harwood
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=a9965b8b-116d-205d-bd55-5d728009b2a2@redhat.com \
--to=carlos@redhat.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=rharwood@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).