From: Andrea Claudi <aclaudi@redhat.com>
To: Phil Sutter <phil@nwl.cc>, Andrea Claudi <aclaudi@redhat.com>,
linux-netdev <netdev@vger.kernel.org>,
Stephen Hemminger <stephen@networkplumber.org>,
David Ahern <dsahern@gmail.com>
Subject: Re: [PATCH iproute2 2/2] lib/fs: Fix single return points for get_cgroup2_*
Date: Sat, 19 Dec 2020 00:29:05 +0100 [thread overview]
Message-ID: <CAPpH65zBxNo9W3VnVsSBfNsGwvVyyw5ZMnHzqSpmMuj7NbaYJQ@mail.gmail.com> (raw)
In-Reply-To: <20201218230835.GY28824@orbyte.nwl.cc>
On Sat, Dec 19, 2020 at 12:08 AM Phil Sutter <phil@nwl.cc> wrote:
>
> On Fri, Dec 18, 2020 at 08:09:23PM +0100, Andrea Claudi wrote:
> > Functions get_cgroup2_id() and get_cgroup2_path() uncorrectly performs
> > cleanup on the single return point. Both of them may get to use close()
> > with a negative argument, if open() fails.
> >
> > Fix this adding proper labels and gotos to make sure we clean up only
> > resources we are effectively used before.
>
> Since free(NULL) is OK according to POSIX, the fds are initialized to -1
> and open() returns -1 on error, you may simplify these
> changes down to making the close() calls conditional:
>
> | if (fd >= 0)
> | close(fd);
>
> Cheers, Phil
>
Thanks for the suggestion, Phil. Will do in v2.
prev parent reply other threads:[~2020-12-18 23:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 19:09 [PATCH iproute2 0/2] Some fixes to lib/fs.c Andrea Claudi
2020-12-18 19:09 ` [PATCH iproute2 1/2] lib/fs: avoid double call to mkdir on make_path() Andrea Claudi
2020-12-18 22:59 ` Phil Sutter
2020-12-18 19:09 ` [PATCH iproute2 2/2] lib/fs: Fix single return points for get_cgroup2_* Andrea Claudi
2020-12-18 23:08 ` Phil Sutter
2020-12-18 23:29 ` Andrea Claudi [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=CAPpH65zBxNo9W3VnVsSBfNsGwvVyyw5ZMnHzqSpmMuj7NbaYJQ@mail.gmail.com \
--to=aclaudi@redhat.com \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=phil@nwl.cc \
--cc=stephen@networkplumber.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).