evalute: don't BUG on unexpected base datatype
Florian Westphal
maintainerPATCH 1/1 evalute: don't BUG on unexpected base datatype
Included bogo will cause a crash but this is the evaluation stage where we can just emit an error instead.
---
I wonder if we should just replace all BUGs in evaluate.c with expr_error() calls, it avoids constant whack-a-mole.
src/evaluate.c | 3 ++- .../bogons/nft-f/invalid_basetype_verdict_assert | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/shell/testcases/bogons/nft-f/invalid_basetype_verdict_assert
src/evaluate.c +2 -1
@@ -482,7 +482,8 @@ static int expr_evaluate_value(struct eval_ctx *ctx, struct expr **expr)return -1 ;break ;default : -BUG ("invalid basetype %s\n" ,expr_basetype (*expr)->name); +return expr_error (ctx->msgs, *expr,"Unexpected basetype %s" , +expr_basetype (*expr)->name); }return 0 ; }
tests/shell/testcases/bogons/nft-f/invalid_basetype_verdict_assert new file +11 -0
@@ -0,0 +1,11 @@ +table ip t { + map m { + type ipv4_addr . inet_service : ipv4_addr . verdict + elements = { 10.0.0.1 . 42 : 10.1.1.1 . 0 } + } + + chain c { + type nat hook prerouting priority dstnat; policy accept; + dnat ip to ip saddr . tcp dport map @m + } +}
Signature · 1 line
2.49.0
Phil Sutter
reviewerQuoted 7 lines · Florian Westphal
Included bogo will cause a crash but this is the evaluation stage where we can just emit an error instead.
Signed-off-by Florian Westphal <[email protected]>---
I wonder if we should just replace all BUGs inevaluate.cwithexpr_error()calls, it avoids constant whack-a-mole.
I guess the expectation was that bison catches these but I fear JSON parser has weakened that quite a bit.
I wish libnftables to well-behave in error cases unless critical ones like ENOMEM.
Cheers, Phil
Pablo Neira Ayuso
maintainerQuoted 8 lines · Phil Sutter
Quoted 7 lines · Florian Westphal
Included bogo will cause a crash but this is the evaluation stage where we can just emit an error instead.
Signed-off-by Florian Westphal <[email protected]>---
I wonder if we should just replace all BUGs inevaluate.cwithexpr_error()calls, it avoids constant whack-a-mole.
I think that can help uncover bugs, or are those json induced bugs?
Quoted 2 lines
I guess the expectation was that bison catches these but I fear JSON parser has weakened that quite a bit.
It would be good to harden json parser to reject trivial non-sense, no need to postpone this to the evaluation phase. If fuzzer can help in that regard. I understand some issues can be more easily identified from the evaluation step. I am not telling to only handle this from the parser, I mean "it depends" on the issue.
Quoted 2 lines
I wish libnftables to well-behave in error cases unless critical ones like ENOMEM.
Yes, I guess that's completary to my request above.
Florian Westphal
maintainerQuoted 4 lines · Pablo Neira Ayuso
Quoted 2 lines
Quoted 2 lines
I wonder if we should just replace all BUGs in
evaluate.cwithexpr_error()calls, it avoids constant whack-a-mole.I think that can help uncover bugs, or are those json induced bugs?
This one is bison, see included bogon input.
I meant in general.
How do these BUGs help at all?
Pablo Neira Ayuso
maintainerHi Florian,
Quoted 7 lines · Florian Westphal
Quoted 4 lines · Pablo Neira Ayuso
Quoted 2 lines
Quoted 2 lines
I wonder if we should just replace all BUGs in
evaluate.cwithexpr_error()calls, it avoids constant whack-a-mole.I think that can help uncover bugs, or are those json induced bugs?
This one is bison, see included bogon input.
For this particular case I think it makes sense to turn it into error.
Nitpick for this patch: I'd suggest this error:
+ return expr_error(ctx->msgs, *expr, "Unexpected datatype %s",
+ (*expr)->dtype->name);
Which results in:
[...]
ruleset:3:61-67: Error: Unexpected datatype verdict
type ipv4_addr . inet_service : ipv4_addr . verdict
^^^^^^^
Quoted 1 line
I meant in general.
It's not so straight forward, I have quickly browsed the existing BUG() calls and, unlike this one, they are mostly trapping nonsense, I guess we can find a way to keep them around while not invoking assert().
Quoted 1 line
How do these BUGs help at all?
Maybe you can turn them into error record adding "BUG:" prefix if you prefer, I guess that will not crash a daemon process which is your concern?
ie. add expr_bug() to highlight an input is triggering a buggy internal state so this can still be reported without crashing the daemon process?