On 2022-04-05, at 13:15:45 +0200, Florian Westphal wrote: > Jeremy Sowden <jeremy@xxxxxxxxxx> wrote: > > If the symbol-table passed to `ct_label2str` is `NULL`, return `NULL`. > > It would be nice to describe why, not what. > Does this fix a crash when the label file is missing? I've been putting debug logging in various places while developing and testing things. Here's a function for dumping expressions to stderr: static inline void dbg_print_expr(const char *func, const char *name, const struct expr *expr) { struct output_ctx *dbgctx = &(struct output_ctx) { .output_fp = stderr }; nft_print(dbgctx, "%s: %s = (%s, %u, %s, %s) { ", func, name, expr_ops(expr)->name, expr->len, expr->dtype ? expr->dtype->name : "", byteorder_names[expr->byteorder]); expr_print(expr, dbgctx); nft_print(dbgctx, " }\n"); } There are two problems with this. Firstly, the `byteorder_names` array is defined in src/evaluate.c and so this function cannot be used elsewhere. Secondly, the symbol-tables in the output context are not initialized, which results in crashes when trying to print symbolic constants and CT labels. Patch 3 fixes the former problem by moving the `byteorder_names` array, and patches 4 & 5 fix the latter problem by adding NULL checks before trying to dereference the symbol-tables. They seemed like small, low-impact changes that could be upstreamed, so that I didn't have to carry them. J.
Attachment:
signature.asc
Description: PGP signature