[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201218230835.GY28824@orbyte.nwl.cc>
Date: Sat, 19 Dec 2020 00:08:35 +0100
From: Phil Sutter <phil@....cc>
To: Andrea Claudi <aclaudi@...hat.com>
Cc: netdev@...r.kernel.org, stephen@...workplumber.org,
dsahern@...il.com
Subject: Re: [PATCH iproute2 2/2] lib/fs: Fix single return points for
get_cgroup2_*
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
Powered by blists - more mailing lists