From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] segtree: memleak in error path of the set to segtree conversion
Date: Thu, 17 Jun 2021 12:54:48 +0200 [thread overview]
Message-ID: <20210617105448.17190-1-pablo@netfilter.org> (raw)
Release the array of intervals and the segtree in case of error,
otherwise these structures and objects are never released:
SUMMARY: AddressSanitizer: 2864 byte(s) leaked in 37 allocation(s).
Moreover, improve existing a test coverage of this error path.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/segtree.c | 16 ++++++++++++++--
tests/py/inet/ip.t | 2 +-
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/segtree.c b/src/segtree.c
index 5eaf684578bf..f721954f76eb 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -288,6 +288,7 @@ out:
return 0;
err:
+ mpz_clear(p);
errno = EEXIST;
if (new->expr->etype == EXPR_MAPPING) {
new_expr = new->expr->left;
@@ -437,7 +438,7 @@ static int set_to_segtree(struct list_head *msgs, struct set *set,
{
struct elementary_interval **intervals;
struct expr *i, *next;
- unsigned int n;
+ unsigned int n, m;
int err = 0;
/* We are updating an existing set with new elements, check if the new
@@ -467,8 +468,19 @@ static int set_to_segtree(struct list_head *msgs, struct set *set,
*/
for (n = 0; n < init->size; n++) {
err = ei_insert(msgs, tree, intervals[n], merge);
- if (err < 0)
+ if (err < 0) {
+ struct elementary_interval *ei;
+ struct rb_node *node, *next;
+
+ for (m = n; m < init->size; m++)
+ ei_destroy(intervals[m]);
+
+ rb_for_each_entry_safe(ei, node, next, &tree->root, rb_node) {
+ ei_remove(tree, ei);
+ ei_destroy(ei);
+ }
break;
+ }
}
xfree(intervals);
diff --git a/tests/py/inet/ip.t b/tests/py/inet/ip.t
index 86604a6363dd..ac5b825e4a34 100644
--- a/tests/py/inet/ip.t
+++ b/tests/py/inet/ip.t
@@ -8,4 +8,4 @@
ip saddr . ip daddr . ether saddr { 1.1.1.1 . 2.2.2.2 . ca:fe:ca:fe:ca:fe };ok
ip saddr vmap { 10.0.1.0-10.0.1.255 : accept, 10.0.1.1-10.0.2.255 : drop };fail
-ip saddr vmap { 1.1.1.1-1.1.1.255 : accept, 1.1.1.0-1.1.2.1 : drop};fail
+ip saddr vmap { 3.3.3.3-3.3.3.4 : accept, 1.1.1.1-1.1.1.255 : accept, 1.1.1.0-1.1.2.1 : drop};fail
--
2.20.1
reply other threads:[~2021-06-17 10:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210617105448.17190-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--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).