From: Christian Marangi <ansuelsmth@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Christian Marangi <ansuelsmth@gmail.com>
Subject: [iptables PATCH] xshared: fix memory leak in should_load_proto
Date: Mon, 29 May 2023 19:18:46 +0200 [thread overview]
Message-ID: <20230529171846.10616-1-ansuelsmth@gmail.com> (raw)
With the help of a Coverity Scan, it was pointed out that it's present a
memory leak in the corner case where find_proto is not NULL in the
function should_load_proto. find_proto return a struct xtables_match
pointer from xtables_find_match that is allocated but never freed.
Correctly free the found proto in the corner case where find_proto
succeed.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
iptables/xshared.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/iptables/xshared.c b/iptables/xshared.c
index 17aed04e..0beacfdc 100644
--- a/iptables/xshared.c
+++ b/iptables/xshared.c
@@ -113,11 +113,16 @@ find_proto(const char *pname, enum xtables_tryload tryload,
*/
static bool should_load_proto(struct iptables_command_state *cs)
{
+ struct xtables_match *proto;
+
if (cs->protocol == NULL)
return false;
- if (find_proto(cs->protocol, XTF_DONT_LOAD,
- cs->options & OPT_NUMERIC, NULL) == NULL)
+ proto = find_proto(cs->protocol, XTF_DONT_LOAD,
+ cs->options & OPT_NUMERIC, NULL);
+ if (proto == NULL)
return true;
+
+ free(proto);
return !cs->proto_used;
}
--
2.39.2
next reply other threads:[~2023-05-29 17:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-29 17:18 Christian Marangi [this message]
2023-05-30 13:04 ` [iptables PATCH] xshared: fix memory leak in should_load_proto Phil Sutter
2023-05-30 16:11 ` Jan Engelhardt
2023-06-16 16:22 ` Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230529171846.10616-1-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).