Skip to content

Commit 1dbc104

Browse files
committed
netlink: Check for NULL return from npt_alloc()
Reviewed by: glebius, pouria Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57171
1 parent 50caa0e commit 1dbc104

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

sys/netlink/netlink_message_parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ nlmsg_report_cookie_u32(struct nl_pstate *npt, uint32_t val)
122122
{
123123
struct nlattr *nla = npt_alloc(npt, sizeof(*nla) + sizeof(uint32_t));
124124

125+
if (nla == NULL)
126+
return;
125127
nla->nla_type = NLMSGERR_ATTR_COOKIE;
126128
nla->nla_len = sizeof(*nla) + sizeof(uint32_t);
127129
memcpy(nla + 1, &val, sizeof(uint32_t));

sys/netlink/route/iface_drivers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ _nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp)
155155
sizeof(ifindex) + NL_ITEM_ALIGN(ifname_len + 1);
156156
struct nlattr *nla_cookie = npt_alloc(npt, nla_len);
157157

158+
if (nla_cookie == NULL)
159+
return;
160+
158161
/* Nested TLV */
159162
nla_cookie->nla_len = nla_len;
160163
nla_cookie->nla_type = NLMSGERR_ATTR_COOKIE;

sys/netlink/route/rt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs,
896896
int num_nhops = attrs->rta_multipath->num_nhops;
897897
struct weightened_nhop *wn = npt_alloc(npt, sizeof(*wn) * num_nhops);
898898

899+
if (wn == NULL) {
900+
*perror = ENOMEM;
901+
return (NULL);
902+
}
899903
for (int i = 0; i < num_nhops; i++) {
900904
struct rta_mpath_nh *mpnh = &attrs->rta_multipath->nhops[i];
901905

0 commit comments

Comments
 (0)