@@ -87,6 +87,11 @@ static int tipc_skb_tailroom(struct sk_buff *skb)
8787 return limit ;
8888}
8989
90+ static inline int TLV_GET_DATA_LEN (struct tlv_desc * tlv )
91+ {
92+ return TLV_GET_LEN (tlv ) - TLV_SPACE (0 );
93+ }
94+
9095static int tipc_add_tlv (struct sk_buff * skb , u16 type , void * data , u16 len )
9196{
9297 struct tlv_desc * tlv = (struct tlv_desc * )skb_tail_pointer (skb );
@@ -166,6 +171,11 @@ static struct sk_buff *tipc_get_err_tlv(char *str)
166171 return buf ;
167172}
168173
174+ static inline bool string_is_valid (char * s , int len )
175+ {
176+ return memchr (s , '\0' , len ) ? true : false;
177+ }
178+
169179static int __tipc_nl_compat_dumpit (struct tipc_nl_compat_cmd_dump * cmd ,
170180 struct tipc_nl_compat_msg * msg ,
171181 struct sk_buff * arg )
@@ -750,13 +760,18 @@ static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd,
750760{
751761 char * name ;
752762 struct nlattr * link ;
763+ int len ;
753764
754765 name = (char * )TLV_DATA (msg -> req );
755766
756767 link = nla_nest_start (skb , TIPC_NLA_LINK );
757768 if (!link )
758769 return - EMSGSIZE ;
759770
771+ len = min_t (int , TLV_GET_DATA_LEN (msg -> req ), TIPC_MAX_LINK_NAME );
772+ if (!string_is_valid (name , len ))
773+ return - EINVAL ;
774+
760775 if (nla_put_string (skb , TIPC_NLA_LINK_NAME , name ))
761776 return - EMSGSIZE ;
762777
0 commit comments