From: Nicolas Iooss <nicolas.iooss@m4x.org>
To: jwcart2 <jwcart2@tycho.nsa.gov>
Cc: selinux@vger.kernel.org
Subject: Re: [Non-DoD Source] [PATCH 1/1] libsepol/cil: silence static analyser's use-after-free warning
Date: Tue, 12 Feb 2019 22:01:24 +0100 [thread overview]
Message-ID: <CAJfZ7==NtXZBnb1MvdG4Hn97Lhaf3h1tMr=EGXAbD+rXS-9b_A@mail.gmail.com> (raw)
In-Reply-To: <d1643ffa-0e04-552f-9903-fa1f111029df@tycho.nsa.gov>
On Mon, Feb 11, 2019 at 8:06 PM jwcart2 <jwcart2@tycho.nsa.gov> wrote:
>
> On 2/6/19 4:07 PM, Nicolas Iooss wrote:
> > clang's static analyze reports a use-after-free in
> > __cil_expr_to_string(), when __cil_expr_to_string_helper() does not
> > modify its third parameter (variable s1 here) in this loop:
> >
> > for (curr = curr->next; curr; curr = curr->next) {
> > __cil_expr_to_string_helper(curr, flavor, &s1);
> > cil_asprintf(&c2, "%s %s", c1, s1);
> > free(c1);
> > free(s1);
> > c1 = c2;
> > }
> >
> > Silence this warning by making sure s1 is always NULL at the beginning
> > of every iteration of the loop.
> >
> > Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
>
> Acked-by: James Carter <jwcart2@tycho.nsa.gov>
Merged.
Nicolas
> > ---
> > libsepol/cil/src/cil_binary.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c
> > index a10c3763bea4..e2eb3ebe8ff3 100644
> > --- a/libsepol/cil/src/cil_binary.c
> > +++ b/libsepol/cil/src/cil_binary.c
> > @@ -2075,6 +2075,7 @@ static void __cil_expr_to_string(struct cil_list *expr, enum cil_flavor flavor,
> > char *c2 = NULL;
> > __cil_expr_to_string_helper(curr, flavor, &c1);
> > for (curr = curr->next; curr; curr = curr->next) {
> > + s1 = NULL;
> > __cil_expr_to_string_helper(curr, flavor, &s1);
> > cil_asprintf(&c2, "%s %s", c1, s1);
> > free(c1);
> >
>
>
> --
> James Carter <jwcart2@tycho.nsa.gov>
> National Security Agency
prev parent reply other threads:[~2019-02-12 21:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-06 21:07 [PATCH 1/1] libsepol/cil: silence static analyser's use-after-free warning Nicolas Iooss
2019-02-11 19:06 ` [Non-DoD Source] " jwcart2
2019-02-12 21:01 ` Nicolas Iooss [this message]
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='CAJfZ7==NtXZBnb1MvdG4Hn97Lhaf3h1tMr=EGXAbD+rXS-9b_A@mail.gmail.com' \
--to=nicolas.iooss@m4x.org \
--cc=jwcart2@tycho.nsa.gov \
--cc=selinux@vger.kernel.org \
/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 NNTP newsgroup(s).