From: jwcart2 <jwcart2@tycho.nsa.gov>
To: Nicolas Iooss <nicolas.iooss@m4x.org>, selinux@vger.kernel.org
Subject: Re: [Non-DoD Source] [PATCH 1/1] libsepol/cil: silence static analyser's use-after-free warning
Date: Mon, 11 Feb 2019 14:06:33 -0500 [thread overview]
Message-ID: <d1643ffa-0e04-552f-9903-fa1f111029df@tycho.nsa.gov> (raw)
In-Reply-To: <20190206210752.11828-1-nicolas.iooss@m4x.org>
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>
> ---
> 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
next prev parent reply other threads:[~2019-02-11 19:06 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 ` jwcart2 [this message]
2019-02-12 21:01 ` [Non-DoD Source] " Nicolas Iooss
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=d1643ffa-0e04-552f-9903-fa1f111029df@tycho.nsa.gov \
--to=jwcart2@tycho.nsa.gov \
--cc=nicolas.iooss@m4x.org \
--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).