]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: fix stack overflow with huge priority string
authorFlorian Westphal <fw@strlen.de>
Fri, 15 Dec 2023 09:19:02 +0000 (10:19 +0100)
committerFlorian Westphal <fw@strlen.de>
Fri, 15 Dec 2023 12:02:56 +0000 (13:02 +0100)
Alternative would be to refactor this and move this into the parsers
(bison, json) instead of this hidden re-parsing.

Fixes: 627c451b2351 ("src: allow variables in the chain priority specification")
Signed-off-by: Florian Westphal <fw@strlen.de>
src/evaluate.c
tests/shell/testcases/bogons/nft-f/huge_chain_prio [new file with mode: 0644]

index 87cd68d3468aed95b081504ef4671572db925ca9..5ddbde42c360b30a2e502fc99ef26edf0cd870ca 100644 (file)
@@ -4897,7 +4897,7 @@ static bool evaluate_priority(struct eval_ctx *ctx, struct prio_spec *prio,
                        NFT_NAME_MAXLEN);
        loc = prio->expr->location;
 
-       if (sscanf(prio_str, "%s %c %d", prio_fst, &op, &prio_snd) < 3) {
+       if (sscanf(prio_str, "%255s %c %d", prio_fst, &op, &prio_snd) < 3) {
                priority = std_prio_lookup(prio_str, family, hook);
                if (priority == NF_IP_PRI_LAST)
                        return false;
diff --git a/tests/shell/testcases/bogons/nft-f/huge_chain_prio b/tests/shell/testcases/bogons/nft-f/huge_chain_prio
new file mode 100644 (file)
index 0000000..41f8061
--- /dev/null
@@ -0,0 +1,5 @@
+table t {
+        chain c {
+                type filter hook input priority srcnDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD#DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD; policy accept;
+        }
+}