genl: Fix descriptor leak in get_genl_kind()
Subsystems (2)
PATCH 1/1 genl: Fix descriptor leak in get_genl_kind()
Signed-off-by Maks Mishin <[email protected]>
--- genl/genl.c | 3 +++ 1 file changed, 3 insertions(+)
genl/genl.c +3 -0
@@ -71,6 +71,9 @@ static struct genl_util *get_genl_kind(const char *str)snprintf (buf,sizeof (buf),"%s_genl_util" , str); f =dlsym (dlh, buf); +if (dlh !=NULL ) +dlclose (dlh); +if (f ==NULL ) goto noexist; reg:
Signature · 1 line
2.30.2
Quoted 1 line · Maks Mishin
Signed-off-by Maks Mishin <[email protected]>
The subject should say [PATCH iproute2] or [PATCH iproute2-next] since it targets that project.
Quoted 9 lines
--- genl/genl.c | 3 +++ 1 file changed, 3 insertions(+)genl/genl.c +0
-0
genl/genl.c static struct genl_util *get_genl_kind(const char *str) · line 75
Quoted 5 lines
genl/genl.c +2
-0@@ -71,6 +71,9 @@ static struct genl_util *get_genl_kind(const char *str)snprintf (buf,sizeof (buf),"%s_genl_util" , str); f =dlsym (dlh, buf); +if (dlh !=NULL ) +dlclose (dlh);
This is broken. If the earlier dlopen() actually loaded a .so then this dlclose() will close it again, before f gets used. When f gets dereferenced later, the program will crash. If this works at all, it is because dlopen(NULL, ...) returns a handle to the main program, so dlclose() doesn't unload it.
My assumption is that the author is leaving resources to be released at program exit. It is a short-lived command line utility after all.
Quoted 4 lines
genl/genl.c +1
-0+if (f ==NULL ) goto noexist; reg: