diff mbox series

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

Message ID 20220623180951.86277-1-pablo@netfilter.org
State Accepted
Delegated to: Pablo Neira
Headers show
Series [nft,1/2] intervals: fix crash when trying to remove element in empty set | expand

Commit Message

Pablo Neira Ayuso June 23, 2022, 6:09 p.m. UTC
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@netfilter.org>
---
 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

Comments

Pablo Neira Ayuso June 27, 2022, 10:38 a.m. UTC | #1
On Thu, Jun 23, 2022 at 08:09:50PM +0200, Pablo Neira Ayuso wrote:
> The set deletion routine expects an initialized set, otherwise it crashes.

This series are now in master.
diff mbox series

Patch

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