]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: do not crash if to-be-printed flowtable lacks priority
authorFlorian Westphal <fw@strlen.de>
Fri, 12 Jan 2024 12:32:17 +0000 (13:32 +0100)
committerFlorian Westphal <fw@strlen.de>
Sun, 16 Jun 2024 11:39:23 +0000 (13:39 +0200)
Print an empty flowtable rather than crashing when dereferencing
flowtable->priority.expr (its NULL).

Signed-off-by: Florian Westphal <fw@strlen.de>
src/rule.c
tests/shell/testcases/bogons/flowtable-no-priority-crash [new file with mode: 0644]

index 65ff0fbbe21f1fc49149686eb85bdaee1f373d47..545f9b2b54631120213159a3b1f2cb932c1adf21 100644 (file)
@@ -2107,12 +2107,15 @@ static void flowtable_print_declaration(const struct flowtable *flowtable,
        if (nft_output_handle(octx))
                nft_print(octx, " # handle %" PRIu64, flowtable->handle.handle.id);
        nft_print(octx, "%s", opts->nl);
-       nft_print(octx, "%s%shook %s priority %s%s",
-                 opts->tab, opts->tab,
-                 hooknum2str(NFPROTO_NETDEV, flowtable->hook.num),
-                 prio2str(octx, priobuf, sizeof(priobuf), NFPROTO_NETDEV,
-                          flowtable->hook.num, flowtable->priority.expr),
-                 opts->stmt_separator);
+
+       if (flowtable->priority.expr) {
+               nft_print(octx, "%s%shook %s priority %s%s",
+                         opts->tab, opts->tab,
+                         hooknum2str(NFPROTO_NETDEV, flowtable->hook.num),
+                         prio2str(octx, priobuf, sizeof(priobuf), NFPROTO_NETDEV,
+                                  flowtable->hook.num, flowtable->priority.expr),
+                         opts->stmt_separator);
+       }
 
        if (flowtable->dev_array_len > 0) {
                nft_print(octx, "%s%sdevices = { ", opts->tab, opts->tab);
diff --git a/tests/shell/testcases/bogons/flowtable-no-priority-crash b/tests/shell/testcases/bogons/flowtable-no-priority-crash
new file mode 100644 (file)
index 0000000..b327a2b
--- /dev/null
@@ -0,0 +1,6 @@
+reset rules
+table inet filter {
+       flowtable f {
+               devices = { lo }
+       }
+}