ll_map: Fix descriptor leak in ll_link_get()
Subsystems (3)
PATCH 1/1 ll_map: Fix descriptor leak in ll_link_get()
Found by RASU JSC
Signed-off-by Maks Mishin <[email protected]>
--- lib/ll_map.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/ll_map.c +3 -1
@@ -278,8 +278,10 @@ static int ll_link_get(const char *name, int index)struct nlmsghdr *answer;int rc =0 ; -if (rtnl_open (&rth,0 ) <0 ) +if (rtnl_open (&rth,0 ) <0 ) { +rtnl_close (&rth);return 0 ; + }addattr32 (&req.n,sizeof (req),IFLA_EXT_MASK , filt_mask);if (name)
Signature · 1 line
2.30.2
Quoted 12 lines · Maks Mishin
Found by RASU JSC
Signed-off-by Maks Mishin <[email protected]>--- lib/ll_map.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)lib/ll_map.c +0
-0
lib/ll_map.c static int ll_link_get(const char *name, int index) · line 282
Quoted 6 lines
lib/ll_map.c +2
-1@@ -278,8 +278,10 @@ static int ll_link_get(const char *name, int index)struct nlmsghdr *answer;int rc =0 ; -if (rtnl_open (&rth,0 ) <0 ) +if (rtnl_open (&rth,0 ) <0 ) { +rtnl_close (&rth);
There's no need to call rtnl_close() if the call to rtnl_open() just failed.
Quoted 5 lines
lib/ll_map.c +1
-0return 0 ; + }addattr32 (&req.n,sizeof (req),IFLA_EXT_MASK , filt_mask);if (name)
Quoted 13 lines · On Wed, 7 Feb 2024 23:32:39 +0300 Maks Mishin <[email protected]> wrote:
Found by RASU JSC
Signed-off-by Maks Mishin <[email protected]>--- lib/ll_map.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)lib/ll_map.c +0
-0@@ -278,8 +278,10 @@ static int ll_link_get(const char *name, int index)struct nlmsghdr *answer;
lib/ll_map.c static int ll_link_get(const char *name, int index) · line 287
Quoted 10 lines
lib/ll_map.c +3
-1int rc =0 ; -if (rtnl_open (&rth,0 ) <0 ) +if (rtnl_open (&rth,0 ) <0 ) { +rtnl_close (&rth);return 0 ; + }addattr32 (&req.n,sizeof (req),IFLA_EXT_MASK , filt_mask);if (name)
Same as previous patch.
This doesn't make sense, the error path in rtnl_open cleans up itself. Do you have a reproducer or is this just some static analyzer?