[PATCH nft 1/2] intervals: fix crash when trying to remove element in empty set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The set deletion routine expects an initialized set, otherwise it crashes.

Fixes: 3e8d934e4f72 ("intervals: support to partial deletion with automerge")
Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
---
 src/intervals.c                     |  6 +++++-
 tests/shell/testcases/sets/errors_0 | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100755 tests/shell/testcases/sets/errors_0

diff --git a/src/intervals.c b/src/intervals.c
index dcc06d18d594..c21b3ee0ad60 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -475,7 +475,11 @@ int set_delete(struct list_head *msgs, struct cmd *cmd, struct set *set,
 	if (set->automerge)
 		automerge_delete(msgs, set, init, debug_mask);
 
-	set_to_range(existing_set->init);
+	if (existing_set->init) {
+		set_to_range(existing_set->init);
+	} else {
+		existing_set->init = set_expr_alloc(&internal_location, set);
+	}
 
 	list_splice_init(&init->expressions, &del_list);
 
diff --git a/tests/shell/testcases/sets/errors_0 b/tests/shell/testcases/sets/errors_0
new file mode 100755
index 000000000000..2960b694c67c
--- /dev/null
+++ b/tests/shell/testcases/sets/errors_0
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+set -e
+
+RULESET="table ip x {
+	set y {
+		type ipv4_addr
+		flags interval
+	}
+}
+
+delete element ip x y { 2.3.4.5 }"
+
+$NFT -f - <<< $RULESET || exit 0
-- 
2.30.2




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux