ipaddrlabel: Fix descriptor leak in flush_addrlabel()
Subsystems (2)
PATCH 1/1 ipaddrlabel: Fix descriptor leak in flush_addrlabel()
Added closure of descriptor rth2.fd created by rtnl_open() when returning from function.
--- ip/ipaddrlabel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
ip/ipaddrlabel.c +3 -1
@@ -201,8 +201,10 @@ static int flush_addrlabel(struct nlmsghdr *n, void *arg) n->nlmsg_type =RTM_DELADDRLABEL ; n->nlmsg_flags =NLM_F_REQUEST ; -if (rtnl_open (&rth2,0 ) <0 ) +if (rtnl_open (&rth2,0 ) <0 ) { +rtnl_close (&rth2);return -1 ; + }if (rtnl_talk (&rth2, n,NULL ) <0 )return -2 ;
Signature · 1 line
2.30.2
Quoted 13 lines · Maks Mishin
Added closure of descriptor
rth2.fdcreated byrtnl_open()when returning from function.Signed-off-by Maks Mishin <[email protected]>--- ip/ipaddrlabel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)ip/ipaddrlabel.c +0
-0
ip/ipaddrlabel.c static int flush_addrlabel(struct nlmsghdr *n, void *arg) · line 205
Quoted 6 lines
ip/ipaddrlabel.c +2
-1@@ -201,8 +201,10 @@ static int flush_addrlabel(struct nlmsghdr *n, void *arg) n->nlmsg_type =RTM_DELADDRLABEL ; n->nlmsg_flags =NLM_F_REQUEST ; -if (rtnl_open (&rth2,0 ) <0 ) +if (rtnl_open (&rth2,0 ) <0 ) { +rtnl_close (&rth2);
This change is unnecessary. You're calling rtnl_close() in the case where rtnl_open() just failed so there's nothing to close.
Quoted 5 lines
ip/ipaddrlabel.c +1
-0return -1 ; + }if (rtnl_talk (&rth2, n,NULL ) <0 )return -2 ;
Quoted 14 lines · On Wed, 7 Feb 2024 23:25:42 +0300 Maks Mishin <[email protected]> wrote:
Added closure of descriptor
rth2.fdcreated byrtnl_open()when returning from function.Signed-off-by Maks Mishin <[email protected]>--- ip/ipaddrlabel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)ip/ipaddrlabel.c +0
-0@@ -201,8 +201,10 @@ static int flush_addrlabel(struct nlmsghdr *n, void *arg) n->nlmsg_type =RTM_DELADDRLABEL ;
ip/ipaddrlabel.c static int flush_addrlabel(struct nlmsghdr *n, void *arg) · line 210
Quoted 10 lines
ip/ipaddrlabel.c +3
-1n->nlmsg_flags =NLM_F_REQUEST ; -if (rtnl_open (&rth2,0 ) <0 ) +if (rtnl_open (&rth2,0 ) <0 ) { +rtnl_close (&rth2);return -1 ; + }if (rtnl_talk (&rth2, n,NULL ) <0 )return -2 ;
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?