Skip to contentSkip to conversation

evaluate: init cmd pointer for new on-stack context

PATCH In review Florian Westphal 3 participants 4 messages Mar 4, 2022 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 evaluate: init cmd pointer for new on-stack context

else, this will segfault when trying to print the
"table 'x' doesn't exist" error message.

---
 src/evaluate.c                                   | 1 +
 tests/shell/testcases/chains/0041chain_binding_0 | 6 ++++++
 2 files changed, 7 insertions(+)
src/evaluate.c +1 -0
index 2732f5f49e06..07a4b0ad19b0 100644
@@ -3425,6 +3425,7 @@ static int stmt_evaluate_chain(struct eval_ctx *ctx, struct stmt *stmt)
 			struct eval_ctx rule_ctx = {
 				.nft	= ctx->nft,
 				.msgs	= ctx->msgs,
+				.cmd	= ctx->cmd,
 			};
 			struct handle h2 = {};
 
tests/shell/testcases/chains/0041chain_binding_0 +6 -0
index 59bdbe9f0ba9..806c17535002 100755
@@ -1,5 +1,11 @@
 #!/bin/bash
 
+# no table z, caused segfault in earlier nft releases
+$NFT insert rule inet x y handle 107 'goto { log prefix "MOO! "; }'
+if [ $? -ne 1 ]; then
+	exit 1
+fi
+
 set -e
 
 EXPECTED="table inet x {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines · Florian Westphal

else, this will segfault when trying to print the
"table 'x' doesn't exist" error message.

LGTM, thanks. One nitpick below:

Quoted 23 lines
---
 src/evaluate.c                                   | 1 +
 tests/shell/testcases/chains/0041chain_binding_0 | 6 ++++++
 2 files changed, 7 insertions(+)
src/evaluate.c +1 -0
index 2732f5f49e06..07a4b0ad19b0 100644
@@ -3425,6 +3425,7 @@ static int stmt_evaluate_chain(struct eval_ctx *ctx, struct stmt *stmt)
 			struct eval_ctx rule_ctx = {
 				.nft	= ctx->nft,
 				.msgs	= ctx->msgs,
+				.cmd	= ctx->cmd,
 			};
 			struct handle h2 = {};
 
tests/shell/testcases/chains/0041chain_binding_0 +0 -0
index 59bdbe9f0ba9..806c17535002 100755

tests/shell/testcases/chains/0041chain_binding_0 line 3

Quoted 3 lines
tests/shell/testcases/chains/0041chain_binding_0 +1 -0
@@ -1,5 +1,11 @@
 #!/bin/bash
 
+# no table z, caused segfault in earlier nft releases

this is no table x?

Quoted 11 lines
tests/shell/testcases/chains/0041chain_binding_0 +5 -0
+$NFT insert rule inet x y handle 107 'goto { log prefix "MOO! "; }'
+if [ $? -ne 1 ]; then
+	exit 1
+fi
+
 set -e
 
 EXPECTED="table inet x {
Signature · 1 line
2.34.1
author maintainer
#2 lore raw
Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Florian Westphal

else, this will segfault when trying to print the
"table 'x' doesn't exist" error message.

LGTM, thanks. One nitpick below:

I've pushed it out with the corrected comment.

reviewer
#3 lore raw
In reply to Pablo Neira Ayuso
Quoted 5 lines · Pablo Neira Ayuso
Quoted 2 lines · Florian Westphal

else, this will segfault when trying to print the
"table 'x' doesn't exist" error message.

LGTM, thanks. One nitpick below:

This also fixes the segfault I was trying to avoid with my patch for string_misspell_update(). I had definitely tried Florian's solution, but it didn't work for me. Guess there's a bug in my test env or something. :(

Thanks, Phil