From 9b01d2898839422bb8ee14b6dccffb9d205cfbd7 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 12 May 2022 10:23:28 +0300 Subject: bgpd: Check argv_find() value instead of the index Signed-off-by: Donatas Abraitis --- bgpd/bgp_debug.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'bgpd/bgp_debug.c') diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 0993d6de57..74f9ca49d5 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -627,8 +627,8 @@ static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv, int argc, struct prefix **argv_pp) { struct prefix *argv_p; - struct ethaddr mac; - struct ipaddr ip; + struct ethaddr mac = {}; + struct ipaddr ip = {}; int evpn_type = 0; int mac_idx = 0; int ip_idx = 0; @@ -641,19 +641,19 @@ static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv, if (evpn_type == BGP_EVPN_MAC_IP_ROUTE) { memset(&ip, 0, sizeof(struct ipaddr)); - argv_find(argv, argc, "mac", &mac_idx); - (void)prefix_str2mac(argv[mac_idx + 1]->arg, &mac); + if (argv_find(argv, argc, "mac", &mac_idx)) + (void)prefix_str2mac(argv[mac_idx + 1]->arg, &mac); - argv_find(argv, argc, "ip", &ip_idx); - str2ipaddr(argv[ip_idx + 1]->arg, &ip); + if (argv_find(argv, argc, "ip", &ip_idx)) + str2ipaddr(argv[ip_idx + 1]->arg, &ip); build_evpn_type2_prefix((struct prefix_evpn *)argv_p, &mac, &ip); } else if (evpn_type == BGP_EVPN_IMET_ROUTE) { memset(&ip, 0, sizeof(struct ipaddr)); - argv_find(argv, argc, "ip", &ip_idx); - str2ipaddr(argv[ip_idx + 1]->arg, &ip); + if (argv_find(argv, argc, "ip", &ip_idx)) + str2ipaddr(argv[ip_idx + 1]->arg, &ip); build_evpn_type3_prefix((struct prefix_evpn *)argv_p, ip.ipaddr_v4); -- cgit v1.2.3 From 7aad5e6a38cf2437d6df022199658f855f48f897 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 12 May 2022 10:28:06 +0300 Subject: bgpd: Check and validate return value for str2ipaddr() Signed-off-by: Donatas Abraitis --- bgpd/bgp_debug.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'bgpd/bgp_debug.c') diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 74f9ca49d5..7712274b58 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -642,10 +642,16 @@ static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv, memset(&ip, 0, sizeof(struct ipaddr)); if (argv_find(argv, argc, "mac", &mac_idx)) - (void)prefix_str2mac(argv[mac_idx + 1]->arg, &mac); + if (!prefix_str2mac(argv[mac_idx + 1]->arg, &mac)) { + vty_out(vty, "%% Malformed MAC address\n"); + return CMD_WARNING; + } if (argv_find(argv, argc, "ip", &ip_idx)) - str2ipaddr(argv[ip_idx + 1]->arg, &ip); + if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) { + vty_out(vty, "%% Malformed IP address\n"); + return CMD_WARNING; + } build_evpn_type2_prefix((struct prefix_evpn *)argv_p, &mac, &ip); @@ -653,7 +659,10 @@ static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv, memset(&ip, 0, sizeof(struct ipaddr)); if (argv_find(argv, argc, "ip", &ip_idx)) - str2ipaddr(argv[ip_idx + 1]->arg, &ip); + if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) { + vty_out(vty, "%% Malformed IP address\n"); + return CMD_WARNING; + } build_evpn_type3_prefix((struct prefix_evpn *)argv_p, ip.ipaddr_v4); -- cgit v1.2.3