git: 9b9b3b157a89 - main - libsysdecode: also verify command decoders
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 10 Aug 2026 14:34:23 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=9b9b3b157a89d159108bcd2f5a817392ab915587
commit 9b9b3b157a89d159108bcd2f5a817392ab915587
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2026-08-10 09:22:08 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-08-10 14:33:32 +0000
libsysdecode: also verify command decoders
We already verified that the attribute parser tables were correctly
sorted. Now also verify that the command decoders are too.
While here move the assertions into a constructor so we only run them once.
---
lib/libsysdecode/netlink.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/lib/libsysdecode/netlink.c b/lib/libsysdecode/netlink.c
index 22ccf1fc2acb..e2b49ea12d7c 100644
--- a/lib/libsysdecode/netlink.c
+++ b/lib/libsysdecode/netlink.c
@@ -61,6 +61,7 @@ static const struct nlattr_decoder_set _name = { \
static void nl_decode_attrs_raw(FILE *fp, const struct nlattr *nla_head,
size_t len, const struct nlattr_decoder *ps, size_t pslen);
+static void sysdecode_netlink_pf_constructor(void) __attribute__ ((__constructor__));
static void
nlattr_decode_in6_addr(FILE *fp, const struct nlattr *attr,
@@ -370,6 +371,18 @@ static const struct pfnl_cmd_decoder cmd_decoder[] = {
{ .cmd_num = PFNL_CMD_GET_ADDR, .ds = &addr_decoder },
};
+static inline void
+pfnl_verify_cmd_decoders(const struct pfnl_cmd_decoder *cmds, size_t count)
+{
+ int num = cmds[0].cmd_num;
+
+ for (size_t i = 1; i < count; i++) {
+ const struct pfnl_cmd_decoder *p = &cmds[i];
+ assert(p->cmd_num > num);
+ num = p->cmd_num;
+ }
+}
+
static void
sysdecode_netlink_pf(FILE *fp, const struct genlmsghdr *genl, size_t nlm_len)
{
@@ -412,8 +425,6 @@ 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};
@@ -554,3 +565,10 @@ sysdecode_netlink(FILE *fp, const void *buf, size_t len, int protocol)
fprintf(fp, "}");
return (true);
}
+
+static void
+sysdecode_netlink_pf_constructor(void)
+{
+ NL_VERIFY_DECODERS(all_decoders);
+ pfnl_verify_cmd_decoders(cmd_decoder, nitems(cmd_decoder));
+}