t@FreeBSD.org) id 24f7d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 10 Aug 2026 14:34:22 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Ishan Agrawal From: Kristof Provost Subject: git: 0f2e98c1515d - main - libsysdecode: verify decoder tables are sorted List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0f2e98c1515d2bfc05701d5e19aac16a985ae5f4 Auto-Submitted: auto-generated Date: Mon, 10 Aug 2026 14:34:22 +0000 Message-Id: <6a79e16e.24f7d.46729963@gitrepo.freebsd.org> The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=0f2e98c1515d2bfc05701d5e19aac16a985ae5f4 commit 0f2e98c1515d2bfc05701d5e19aac16a985ae5f4 Author: Ishan Agrawal AuthorDate: 2026-08-09 06:24:18 +0000 Commit: Kristof Provost 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 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};