Skip to contentSkip to conversation

set: Add nft_set_elems_nlmsg_build_payload_check

RFC PATCH New Yuxuan Shui 1 participant 1 message Mar 14, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 set: Add nft_set_elems_nlmsg_build_payload_check

The new function is nft_set_elems_nlmsg_build_payload_check, which checks if the buffer is large enough to hold the payload and returns true on success. This function can be used to guard against buffer overflow.

---
 include/libnftnl/set.h |  2 ++
 src/libnftnl.map       |  2 ++
 src/set_elem.c         | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
include/libnftnl/set.h +2 -0
index fcb1a7e..0eafc5b 100644
@@ -104,6 +104,8 @@ bool nft_set_elem_attr_is_set(const struct nft_set_elem *s, uint16_t attr);
 #define nft_set_elem_nlmsg_build_hdr	nft_nlmsg_build_hdr
 void nft_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set *s);
 void nft_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set_elem *e);
+bool nft_set_elems_nlmsg_build_payload_check(struct nlmsghdr *nlh, size_t buflen, struct nft_set *s);
+bool nft_set_elem_nlmsg_build_payload_check(struct nlmsghdr *nlh, size_t buflen, struct nft_set_elem *e);
 
 int nft_set_elem_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set_elem *s);
 
src/libnftnl.map +2 -0
index 7c4e6ca..746d0c7 100644
@@ -161,6 +161,7 @@ global:
   nft_set_elem_attr_get_str;
   nft_set_elem_attr_get_u32;
   nft_set_elem_nlmsg_build_payload;
+  nft_set_elem_nlmsg_build_payload_check;
   nft_set_elem_nlmsg_parse;
   nft_set_elem_parse;
   nft_set_elem_parse_file;
@@ -168,6 +169,7 @@ global:
   nft_set_elem_fprinf;
 
   nft_set_elems_nlmsg_build_payload;
+  nft_set_elems_nlmsg_build_payload_check;
   nft_set_elems_nlmsg_parse;
 
   nft_set_elems_foreach;
src/set_elem.c +73 -0

85 lines not on this page · raw message

Signature · 1 line
1.9.0