All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Iooss <nicolas.iooss@m4x.org>
To: Petr Lautrbach <plautrba@redhat.com>
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH 3/3] libsemanage: Fix USE_AFTER_FREE defects reported by coverity scan
Date: Thu, 31 Jan 2019 22:57:29 +0100	[thread overview]
Message-ID: <CAJfZ7=kMpqdfbQ4NfHT_5FbY-63N0O2L1xUMBi2MHMnRB=0Y+Q@mail.gmail.com> (raw)
In-Reply-To: <20190131132226.19030-3-plautrba@redhat.com>

On Thu, Jan 31, 2019 at 2:22 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
> ---
>  libsemanage/src/direct_api.c | 21 ++++++++-------------
>  1 file changed, 8 insertions(+), 13 deletions(-)
>
> diff --git a/libsemanage/src/direct_api.c b/libsemanage/src/direct_api.c
> index c58961be..8e4d116d 100644
> --- a/libsemanage/src/direct_api.c
> +++ b/libsemanage/src/direct_api.c
> @@ -1028,7 +1028,7 @@ static int semanage_direct_write_langext(semanage_handle_t *sh,
>
>         fp = NULL;
>
> -       ret = 0;
> +       return 0;
>
>  cleanup:
>         if (fp != NULL) fclose(fp);
> @@ -2177,7 +2177,6 @@ cleanup:
>         semanage_module_info_destroy(sh, modinfo);
>         free(modinfo);
>
> -       if (fp != NULL) fclose(fp);
>         return status;
>  }
>
> @@ -2342,16 +2341,6 @@ static int semanage_direct_get_module_info(semanage_handle_t *sh,
>         free(tmp);
>         tmp = NULL;
>
> -       if (fclose(fp) != 0) {
> -               ERR(sh,
> -                   "Unable to close %s module lang ext file.",
> -                   (*modinfo)->name);
> -               status = -1;
> -               goto cleanup;
> -       }
> -
> -       fp = NULL;
> -
>         /* lookup enabled/disabled status */
>         ret = semanage_module_get_path(sh,
>                                        *modinfo,
> @@ -2395,7 +2384,13 @@ cleanup:
>                 free(modinfos);
>         }
>
> -       if (fp != NULL) fclose(fp);
> +       if (fp != NULL && fclose(fp) != 0) {
> +               ERR(sh,
> +                   "Unable to close %s module lang ext file.",
> +                   (*modinfo)->name);
> +               status = -1;
> +       }
> +
>         return status;
>  }
>
> --
> 2.20.1

After reading this patch, I am wondering what the USE_AFTER_FREE
defects were about. Were there real use-after-fclose bugs that are
fixed by this patch? Or is this patch more about silencing Coverity's
false positives due to difficulties in parsing constructions such as
"fclose(fp);fp = NULL; if(f != NULL)fclose(fp);"? It would be useful
if the patch description contains answers to these questions.

Otherwise the content of the patch looks good to me.

Nicolas


  reply	other threads:[~2019-01-31 21:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-31 13:22 [PATCH 1/3] libsepol: Fix RESOURCE_LEAK defects reported by coverity scan Petr Lautrbach
2019-01-31 13:22 ` [PATCH 2/3] libselinux: " Petr Lautrbach
2019-01-31 21:47   ` Nicolas Iooss
2019-02-06 20:33     ` [PATCH v2] " Petr Lautrbach
2019-02-06 22:40       ` Nicolas Iooss
2019-02-10 18:32         ` Nicolas Iooss
2019-01-31 13:22 ` [PATCH 3/3] libsemanage: Fix USE_AFTER_FREE " Petr Lautrbach
2019-01-31 21:57   ` Nicolas Iooss [this message]
2019-02-01 12:45     ` Petr Lautrbach
2019-01-31 21:17 ` [PATCH 1/3] libsepol: Fix RESOURCE_LEAK " Nicolas Iooss
2019-02-01 18:19   ` [Non-DoD Source] " jwcart2
2019-01-31 21:33 ` Nicolas Iooss
2019-02-01 19:32   ` [Non-DoD Source] " jwcart2
2019-02-01 20:07 ` [Non-DoD Source] " jwcart2

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=kMpqdfbQ4NfHT_5FbY-63N0O2L1xUMBi2MHMnRB=0Y+Q@mail.gmail.com' \
    --to=nicolas.iooss@m4x.org \
    --cc=plautrba@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.