]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: Increase symbolic constant printer robustness
authorPhil Sutter <phil@nwl.cc>
Fri, 10 Oct 2025 12:14:29 +0000 (14:14 +0200)
committerPhil Sutter <phil@nwl.cc>
Thu, 23 Oct 2025 20:48:51 +0000 (22:48 +0200)
Do not segfault if passed symbol table is NULL.

Signed-off-by: Phil Sutter <phil@nwl.cc>
src/datatype.c

index 7effeb33208e766c04728f64576f21c1e9c73247..8e93ead0e8f3616dd97f0d70bcff3fc10e0890a4 100644 (file)
@@ -254,15 +254,19 @@ void symbolic_constant_print(const struct symbol_table *tbl,
        mpz_export_data(constant_data_ptr(val, expr->len), expr->value,
                        expr->byteorder, len);
 
+       if (nft_output_numeric_symbol(octx) || !tbl)
+               goto basetype_print;
+
        for (s = tbl->symbols; s->identifier != NULL; s++) {
                if (val == s->value)
                        break;
        }
-
-       if (s->identifier == NULL || nft_output_numeric_symbol(octx))
-               return expr_basetype(expr)->print(expr, octx);
-
-       nft_print(octx, quotes ? "\"%s\"" : "%s", s->identifier);
+       if (s->identifier) {
+               nft_print(octx, quotes ? "\"%s\"" : "%s", s->identifier);
+               return;
+       }
+basetype_print:
+       expr_basetype(expr)->print(expr, octx);
 }
 
 static void switch_byteorder(void *data, unsigned int len)