@@ -2920,23 +2920,31 @@ int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *in)
29202920 req .rtm .rtm_dst_len = IPV4_MAX_BITLEN ;
29212921 req .rtm .rtm_src_len = IPV4_MAX_BITLEN ;
29222922
2923- nl_attr_put (& req .n , sizeof (req ), RTA_SRC ,
2924- & mroute -> src .ipaddr_v4 ,
2925- sizeof (mroute -> src .ipaddr_v4 ));
2926- nl_attr_put (& req .n , sizeof (req ), RTA_DST ,
2927- & mroute -> grp .ipaddr_v4 ,
2928- sizeof (mroute -> grp .ipaddr_v4 ));
2923+ if (!nl_attr_put (& req .n , sizeof (req ), RTA_SRC , & mroute -> src .ipaddr_v4 ,
2924+ sizeof (mroute -> src .ipaddr_v4 ))) {
2925+ zlog_err ("%s: Failed to put ipv4 RTA_SRC nl attribute" , __func__ );
2926+ return 0 ;
2927+ }
2928+ if (!nl_attr_put (& req .n , sizeof (req ), RTA_DST , & mroute -> grp .ipaddr_v4 ,
2929+ sizeof (mroute -> grp .ipaddr_v4 ))) {
2930+ zlog_err ("%s: Failed to put ipv4 RTA_DST nl attribute" , __func__ );
2931+ return 0 ;
2932+ }
29292933 } else {
29302934 req .rtm .rtm_family = RTNL_FAMILY_IP6MR ;
29312935 req .rtm .rtm_dst_len = IPV6_MAX_BITLEN ;
29322936 req .rtm .rtm_src_len = IPV6_MAX_BITLEN ;
29332937
2934- nl_attr_put (& req .n , sizeof (req ), RTA_SRC ,
2935- & mroute -> src .ipaddr_v6 ,
2936- sizeof (mroute -> src .ipaddr_v6 ));
2937- nl_attr_put (& req .n , sizeof (req ), RTA_DST ,
2938- & mroute -> grp .ipaddr_v6 ,
2939- sizeof (mroute -> grp .ipaddr_v6 ));
2938+ if (!nl_attr_put (& req .n , sizeof (req ), RTA_SRC , & mroute -> src .ipaddr_v6 ,
2939+ sizeof (mroute -> src .ipaddr_v6 ))) {
2940+ zlog_err ("%s: Failed to put ipv6 RTA_SRC nl attribute" , __func__ );
2941+ return 0 ;
2942+ }
2943+ if (!nl_attr_put (& req .n , sizeof (req ), RTA_DST , & mroute -> grp .ipaddr_v6 ,
2944+ sizeof (mroute -> grp .ipaddr_v6 ))) {
2945+ zlog_err ("%s: Failed to put ipv6 RTA_DST nl attribute" , __func__ );
2946+ return 0 ;
2947+ }
29402948 }
29412949
29422950 /*
@@ -2960,7 +2968,10 @@ int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *in)
29602968 else
29612969 actual_table = zvrf -> table_id ;
29622970
2963- nl_attr_put32 (& req .n , sizeof (req ), RTA_TABLE , actual_table );
2971+ if (!nl_attr_put32 (& req .n , sizeof (req ), RTA_TABLE , actual_table )) {
2972+ zlog_err ("%s: Failed to put RTA_TABLE nl attribute" , __func__ );
2973+ return 0 ;
2974+ }
29642975
29652976 suc = netlink_talk (netlink_route_change_read_multicast , & req .n ,
29662977 & zns -> netlink_cmd , zns , false);
@@ -3016,18 +3027,21 @@ static bool _netlink_nexthop_build_group(struct nlmsghdr *n, size_t req_size, ui
30163027 struct rtattr * nest ;
30173028
30183029 nest = nl_attr_nest (n , req_size , NHA_RES_GROUP );
3030+ if (!nest )
3031+ return false;
30193032
3020- nl_attr_put16 (n , req_size , NHA_RES_GROUP_BUCKETS ,
3021- nhgr -> buckets );
3022- nl_attr_put32 (n , req_size , NHA_RES_GROUP_IDLE_TIMER ,
3023- nhgr -> idle_timer * 1000 );
3024- nl_attr_put32 (n , req_size ,
3025- NHA_RES_GROUP_UNBALANCED_TIMER ,
3026- nhgr -> unbalanced_timer * 1000 );
3033+ if (!nl_attr_put16 (n , req_size , NHA_RES_GROUP_BUCKETS , nhgr -> buckets ))
3034+ return false;
3035+ if (!nl_attr_put32 (n , req_size , NHA_RES_GROUP_IDLE_TIMER ,
3036+ nhgr -> idle_timer * 1000 ))
3037+ return false;
3038+ if (!nl_attr_put32 (n , req_size , NHA_RES_GROUP_UNBALANCED_TIMER ,
3039+ nhgr -> unbalanced_timer * 1000 ))
3040+ return false;
30273041 nl_attr_nest_end (n , nest );
30283042
3029- nl_attr_put16 (n , req_size , NHA_GROUP_TYPE ,
3030- NEXTHOP_GRP_TYPE_RES ) ;
3043+ if (! nl_attr_put16 (n , req_size , NHA_GROUP_TYPE , NEXTHOP_GRP_TYPE_RES ))
3044+ return false ;
30313045 }
30323046 }
30333047
@@ -4272,7 +4286,10 @@ static int netlink_request_macs(struct nlsock *netlink_cmd, int family,
42724286 req .n .nlmsg_len = NLMSG_LENGTH (sizeof (struct ifinfomsg ));
42734287 req .ifm .ifi_family = family ;
42744288 if (master_ifindex )
4275- nl_attr_put32 (& req .n , sizeof (req ), IFLA_MASTER , master_ifindex );
4289+ if (!nl_attr_put32 (& req .n , sizeof (req ), IFLA_MASTER , master_ifindex )) {
4290+ zlog_err ("%s: Failed to put IFLA_MASTER nl attribute" , __func__ );
4291+ return -1 ;
4292+ }
42764293
42774294 return netlink_request (netlink_cmd , & req );
42784295}
@@ -4355,18 +4372,31 @@ static int netlink_request_specific_mac(struct zebra_ns *zns, int family,
43554372 req .ndm .ndm_flags = flags ;
43564373 /* req.ndm.ndm_state = NUD_REACHABLE; */
43574374
4358- nl_attr_put (& req .n , sizeof (req ), NDA_LLADDR , mac , 6 );
4375+ if (!nl_attr_put (& req .n , sizeof (req ), NDA_LLADDR , mac , 6 )) {
4376+ zlog_err ("%s: Failed to add NDA_LLADDR nl attribute" , __func__ );
4377+ return -1 ;
4378+ }
43594379
43604380 zif = (struct zebra_if * )ifp -> info ;
43614381 /* Is this a read on a VXLAN interface? */
43624382 if (IS_ZEBRA_IF_VXLAN (ifp )) {
4363- nl_attr_put32 (& req .n , sizeof (req ), NDA_VNI , vni );
4383+ if (!nl_attr_put32 (& req .n , sizeof (req ), NDA_VNI , vni )) {
4384+ zlog_err ("%s: Failed to add NDA_VNI nl attribute" , __func__ );
4385+ return -1 ;
4386+ }
43644387 /* TBD: Why is ifindex not filled in the non-vxlan case? */
43654388 req .ndm .ndm_ifindex = ifp -> ifindex ;
43664389 } else {
4367- if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE (zif ) && vid > 0 )
4368- nl_attr_put16 (& req .n , sizeof (req ), NDA_VLAN , vid );
4369- nl_attr_put32 (& req .n , sizeof (req ), NDA_MASTER , ifp -> ifindex );
4390+ if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE (zif ) && vid > 0 ) {
4391+ if (!nl_attr_put16 (& req .n , sizeof (req ), NDA_VLAN , vid )) {
4392+ zlog_err ("%s: Failed to add NDA_VLAN nl attribute" , __func__ );
4393+ return -1 ;
4394+ }
4395+ }
4396+ if (!nl_attr_put32 (& req .n , sizeof (req ), NDA_MASTER , ifp -> ifindex )) {
4397+ zlog_err ("%s: Failed to add NDA_MASTER nl attribute" , __func__ );
4398+ return -1 ;
4399+ }
43704400 }
43714401
43724402 if (IS_ZEBRA_DEBUG_KERNEL )
@@ -4722,7 +4752,10 @@ static int netlink_request_neigh(struct nlsock *netlink_cmd, int family,
47224752 req .n .nlmsg_len = NLMSG_LENGTH (sizeof (struct ndmsg ));
47234753 req .ndm .ndm_family = family ;
47244754 if (ifindex )
4725- nl_attr_put32 (& req .n , sizeof (req ), NDA_IFINDEX , ifindex );
4755+ if (!nl_attr_put32 (& req .n , sizeof (req ), NDA_IFINDEX , ifindex )) {
4756+ zlog_err ("%s: Failed to put NDA_IFINDEX nl attribute" , __func__ );
4757+ return -1 ;
4758+ }
47264759
47274760 return netlink_request (netlink_cmd , & req );
47284761}
@@ -4802,7 +4835,10 @@ static int netlink_request_specific_neigh_in_vlan(struct zebra_ns *zns,
48024835 req .ndm .ndm_family = AF_INET6 ;
48034836 }
48044837
4805- nl_attr_put (& req .n , sizeof (req ), NDA_DST , & ip -> ip .addr , ipa_len );
4838+ if (!nl_attr_put (& req .n , sizeof (req ), NDA_DST , & ip -> ip .addr , ipa_len )) {
4839+ zlog_err ("%s: Failed to put NDA_DST nl attribute" , __func__ );
4840+ return -1 ;
4841+ }
48064842
48074843 if (IS_ZEBRA_DEBUG_KERNEL )
48084844 zlog_debug ("%s: Tx %s family %s IF %u IP %pIA flags 0x%x" ,
@@ -4983,7 +5019,8 @@ static int netlink_neigh_table_update_ctx(const struct zebra_dplane_ctx *ctx,
49835019 req -> ndtm .ndtm_family = family ;
49845020
49855021 name = family == AF_INET ? "arp_cache" : "ndisc_cache" ;
4986- nl_attr_put (& req -> n , datalen , NDTA_NAME , name , strlen (name ) + 1 );
5022+ if (!nl_attr_put (& req -> n , datalen , NDTA_NAME , name , strlen (name ) + 1 ))
5023+ return 0 ;
49875024 nest = nl_attr_nest (& req -> n , datalen , NDTA_PARMS );
49885025 if (nest == NULL )
49895026 return 0 ;
0 commit comments