From d7c97c8c48c509a52f8be33665d11c97f66cfff1 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 14 Jul 2026 10:02:52 -0400 Subject: [PATCH] MT#55283 extend nfapi_add_binary_str_attr Allow for variable length strings Change-Id: I2a970908b8b948a90abf9524f8a8ce094a04b5cd --- lib/netfilter_api.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/netfilter_api.h b/lib/netfilter_api.h index 94b407abe..63992b715 100644 --- a/lib/netfilter_api.h +++ b/lib/netfilter_api.h @@ -44,15 +44,18 @@ void nfapi_add_attr(nfapi_buf *b, uint16_t type, const void *data, size_t len, c nfapi_add_attr(b, t, &__u, sizeof(__u), f, ##__VA_ARGS__); \ } while (0) -#define nfapi_add_binary_str_attr(b, type, s, fmt, ...) \ - nfapi_add_attr(b, type, &(struct { \ - uint16_t len; \ - char buf[sizeof(s)]; \ - }) { \ - .len = htons(sizeof(s)), \ - .buf = s, \ - }, 2 + sizeof(s), \ - fmt, ##__VA_ARGS__) +#define nfapi_add_binary_str_attr(b, type, s, fmt, ...) do { \ + struct { \ + uint16_t len; \ + char buf[64]; \ + } __attr; \ + ssize_t __len = strlen(s); \ + assert(__len < sizeof(__attr.buf)); \ + __attr.len = htons(__len + 1); \ + strcpy(__attr.buf, (s)); \ + nfapi_add_attr(b, type, &__attr, 2 + __len + 1, \ + fmt, ##__VA_ARGS__); \ +} while (0) void nfapi_nested_begin(nfapi_buf *, uint16_t type, const char *name);