git: 26d1ad5a44e1 - main - netlink: snl_create_genl_msg_request() may fail due to ENOMEM
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 11 Jan 2025 05:00:28 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=26d1ad5a44e17d2d8c48d36755567043349d8b63 commit 26d1ad5a44e17d2d8c48d36755567043349d8b63 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2025-01-11 04:58:08 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2025-01-11 04:58:08 +0000 netlink: snl_create_genl_msg_request() may fail due to ENOMEM Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D48310 --- sys/netlink/netlink_snl_generic.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sys/netlink/netlink_snl_generic.h b/sys/netlink/netlink_snl_generic.h index 32b460c612bd..e2dc4d1bfffe 100644 --- a/sys/netlink/netlink_snl_generic.h +++ b/sys/netlink/netlink_snl_generic.h @@ -33,16 +33,24 @@ /* Genetlink helpers */ static inline struct nlmsghdr * -snl_create_genl_msg_request(struct snl_writer *nw, int genl_family, uint8_t genl_cmd) +snl_create_genl_msg_request(struct snl_writer *nw, uint16_t genl_family, + uint8_t genl_cmd) { + struct nlmsghdr *hdr; + struct genlmsghdr *ghdr; + assert(nw->hdr == NULL); - struct nlmsghdr *hdr = snl_reserve_msg_object(nw, struct nlmsghdr); + hdr = snl_reserve_msg_object(nw, struct nlmsghdr); + if (__predict_false(hdr == NULL)) + return (NULL); hdr->nlmsg_type = genl_family; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; - nw->hdr = hdr; - struct genlmsghdr *ghdr = snl_reserve_msg_object(nw, struct genlmsghdr); + ghdr = snl_reserve_msg_object(nw, struct genlmsghdr); + if (__predict_false(ghdr == NULL)) + return (NULL); ghdr->cmd = genl_cmd; + nw->hdr = hdr; return (hdr); }