From: Phil Sutter Date: Fri, 10 Oct 2025 12:14:29 +0000 (+0200) Subject: datatype: Increase symbolic constant printer robustness X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c2905cd4acdbbbacc0ce96c85309aa2c2878aed6;p=thirdparty%2Fnftables.git datatype: Increase symbolic constant printer robustness Do not segfault if passed symbol table is NULL. Signed-off-by: Phil Sutter --- diff --git a/src/datatype.c b/src/datatype.c index 7effeb33..8e93ead0 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -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)