git: 0f2e98c1515d - main - libsysdecode: verify decoder tables are sorted
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 10 Aug 2026 14:34:22 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=0f2e98c1515d2bfc05701d5e19aac16a985ae5f4
commit 0f2e98c1515d2bfc05701d5e19aac16a985ae5f4
Author: Ishan Agrawal <iagrawal9990@gmail.com>
AuthorDate: 2026-08-09 06:24:18 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-08-10 14:33:32 +0000
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
---
lib/libsysdecode/netlink.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
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};