Thread (6 messages) flat view 6 messages, 2 authors, 2020-12-18

Re: [PATCH iproute2 2/2] lib/fs: Fix single return points for get_cgroup2_*

From: Phil Sutter <phil@nwl.cc>
Date: 2020-12-18 23:09:34

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help