datatype: Increase symbolic constant printer robustness

Do not segfault if passed symbol table is NULL.

Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
Phil Sutter 2025-10-10 14:14:29 +02:00
parent 134b50e5d3
commit c2905cd4ac

View 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)