aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIshan Agrawal <iagrawal9990@gmail.com>2026-08-09 06:24:18 +0000
committerKristof Provost <kp@FreeBSD.org>2026-08-10 14:33:32 +0000
commit0f2e98c1515d2bfc05701d5e19aac16a985ae5f4 (patch)
tree7419cb521b6df297c2480c84ca14a83cbec7f5f0
parent2ef4baaffce0ab71491085e68fefc92eff8e715c (diff)
libsysdecode: verify decoder tables are sorted
Add assertions to validate decoder table ordering required by binary search. Signed-off-by: Ishan Agrawal <iagrawal9990@gmail.com> Sponsored-by: Google LLC (GSoC 2026) Reviewed by: kp
-rw-r--r--lib/libsysdecode/netlink.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/libsysdecode/netlink.c b/lib/libsysdecode/netlink.c
index 2785b23cb98b..22ccf1fc2acb 100644
--- a/lib/libsysdecode/netlink.c
+++ b/lib/libsysdecode/netlink.c
@@ -340,6 +340,28 @@ static const struct nlattr_decoder nla_d_clear_states[] = {
};
NL_DECLARE_ATTR_DECODER(killclear_states_decoder, nla_d_clear_states);
+static inline void
+nl_verify_decoders(const struct nlattr_decoder_set **decoder, size_t count)
+{
+ for (size_t i = 0; i < count; i++) {
+ const struct nlattr_decoder_set *p = decoder[i];
+ for (size_t j = 1; j < p->count; j++) {
+ assert(p->decoders[j].type > p->decoders[j-1].type);
+ }
+ }
+}
+#define NL_VERIFY_DECODERS(_p) nl_verify_decoders((_p), nitems(_p))
+
+static const struct nlattr_decoder_set *all_decoders[] = {
+ &getrules_decoder,
+ &set_limit_decoder,
+ &addr_wrap_decoder,
+ &pool_addr_decoder,
+ &addr_decoder,
+ &rule_addr_decoder,
+ &killclear_states_decoder,
+};
+
static const struct pfnl_cmd_decoder cmd_decoder[] = {
{ .cmd_num = PFNL_CMD_GETRULES, .ds = &getrules_decoder },
{ .cmd_num = PFNL_CMD_KILLSTATES, .ds = &killclear_states_decoder },
@@ -390,6 +412,8 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol)
return (false);
if (family_table == NULL) {
+ NL_VERIFY_DECODERS(all_decoders);
+
family_table = malloc((num_family + 1) *
sizeof(struct name_table));
family_table[num_family] = (struct name_table){0, NULL};