m_tunnel_key: Add check for result hex2mem()
Subsystems (2)
PATCH 1/1 m_tunnel_key: Add check for result hex2mem()
Added check for hex2mem() result to report of error with incorrect args.
Signed-off-by Maks Mishin <[email protected]>
--- tc/m_tunnel_key.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tc/m_tunnel_key.c +4 -1
@@ -575,7 +575,10 @@ static void tunnel_key_print_geneve_options(struct rtattr *attr) data_len =RTA_PAYLOAD (tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA ]);hexstring_n2a (RTA_DATA (tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA ]), data_len, data,sizeof (data)); -hex2mem (data, data_r, data_len); + +if (hex2mem (data, data_r, data_len) <0 ) +invarg ("labels mask must be a hex string\n" , data); + offset += data_len +20 ; rem -= data_len +20 ; i =RTA_DATA (attr) + offset;
Signature · 1 line
2.30.2
Quoted 13 lines · On Sun, 18 Feb 2024 23:40:26 +0300 Maks Mishin <[email protected]> wrote:
Added check for
hex2mem()result to report of error with incorrect args.Signed-off-by Maks Mishin <[email protected]>--- tc/m_tunnel_key.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tc/m_tunnel_key.c +0
-0
tc/m_tunnel_key.c static void tunnel_key_print_geneve_options(struct rtattr *attr) · line 581
Quoted 8 lines
tc/m_tunnel_key.c +4
-1@@ -575,7 +575,10 @@ static void tunnel_key_print_geneve_options(struct rtattr *attr) data_len =RTA_PAYLOAD (tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA ]);hexstring_n2a (RTA_DATA (tb[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_DATA ]), data_len, data,sizeof (data)); -hex2mem (data, data_r, data_len); + +if (hex2mem (data, data_r, data_len) <0 ) +invarg ("labels mask must be a hex string\n" , data); +
invarg() is intended only for use in command line args.
This is where the result of a geneve option from kernel netlink is being parsed. Not user input.
Not sure why hex2mem is needed here at all? The original data is in the netlink message. Doing the inverse is redundant.