diff options
| author | Phil Sutter <phil@nwl.cc> | 2025-10-10 14:14:29 +0200 |
|---|---|---|
| committer | Phil Sutter <phil@nwl.cc> | 2025-10-23 22:48:51 +0200 |
| commit | c2905cd4acdbbbacc0ce96c85309aa2c2878aed6 (patch) | |
| tree | 4ae0f14505ebf2b2a84910e4afedce05b7c8631c /src | |
| parent | 134b50e5d3f185219e09c613d98d6bf9494b1248 (diff) | |
datatype: Increase symbolic constant printer robustness
Do not segfault if passed symbol table is NULL.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src')
| -rw-r--r-- | src/datatype.c | 14 |
1 files changed, 9 insertions, 5 deletions
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) |
