From cc9b06ad5e58968356ab4edf30f3fd9eb7583b47 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 24 Aug 2017 19:45:25 -0400 Subject: [PATCH] eigrpd, ospfd: Cleanup inet_aton return code checking Signed-off-by: Donald Sharp --- eigrpd/eigrp_vty.c | 12 ++++++++++-- ospfd/ospf_vty.c | 30 ++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c index 4a8842f30e..c0f8d36b49 100644 --- a/eigrpd/eigrp_vty.c +++ b/eigrpd/eigrp_vty.c @@ -1267,7 +1267,11 @@ DEFUN (clear_ip_eigrp_neighbors_IP, struct eigrp_neighbor *nbr; struct in_addr nbr_addr; - inet_aton(argv[4]->arg, &nbr_addr); + if (!inet_aton(argv[4]->arg, &nbr_addr)) { + vty_out(vty, "Unable to parse %s", + argv[4]->arg); + return CMD_WARNING; + } /* Check if eigrp process is enabled */ eigrp = eigrp_lookup(); @@ -1370,7 +1374,11 @@ DEFUN (clear_ip_eigrp_neighbors_IP_soft, struct eigrp_neighbor *nbr; struct in_addr nbr_addr; - inet_aton(argv[4]->arg, &nbr_addr); + if (!inet_aton(argv[4]->arg, &nbr_addr)) { + vty_out(vty, "Unable to parse: %s", + argv[4]->arg); + return CMD_WARNING; + } /* Check if eigrp process is enabled */ eigrp = eigrp_lookup(); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 87aef1ea97..96b6fe8bf9 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -2306,7 +2306,10 @@ DEFUN (ospf_neighbor, unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; - inet_aton(argv[idx_ipv4]->arg, &nbr_addr); + if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { + vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); + return CMD_WARNING_CONFIG_FAILED; + } if (argc > 2) priority = strtoul(argv[idx_pri]->arg, NULL, 10); @@ -2343,7 +2346,10 @@ DEFUN (ospf_neighbor_poll_interval, unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; - inet_aton(argv[idx_ipv4]->arg, &nbr_addr); + if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { + vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); + return CMD_WARNING_CONFIG_FAILED; + } interval = strtoul(argv[idx_poll]->arg, NULL, 10); @@ -2374,7 +2380,10 @@ DEFUN (no_ospf_neighbor, int idx_ipv4 = 2; struct in_addr nbr_addr; - inet_aton(argv[idx_ipv4]->arg, &nbr_addr); + if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { + vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); + return CMD_WARNING_CONFIG_FAILED; + } (void)ospf_nbr_nbma_unset(ospf, nbr_addr); @@ -2396,7 +2405,10 @@ DEFUN (no_ospf_neighbor_poll, int idx_ipv4 = 2; struct in_addr nbr_addr; - inet_aton(argv[idx_ipv4]->arg, &nbr_addr); + if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { + vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); + return CMD_WARNING_CONFIG_FAILED; + } (void)ospf_nbr_nbma_unset(ospf, nbr_addr); @@ -6958,7 +6970,10 @@ DEFUN (ip_ospf_area, // Check if we have an address arg and proccess it if (argc == idx + 3) { - inet_aton(argv[idx + 2]->arg, &addr); + if (!inet_aton(argv[idx + 2]->arg, &addr)) { + vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); + return CMD_WARNING_CONFIG_FAILED; + } // update/create address-level params params = ospf_get_if_params((ifp), (addr)); if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { @@ -7017,7 +7032,10 @@ DEFUN (no_ip_ospf_area, // Check if we have an address arg and proccess it if (argc == idx + 3) { - inet_aton(argv[idx + 2]->arg, &addr); + if (!inet_aton(argv[idx + 2]->arg, &addr)) { + vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); + return CMD_WARNING_CONFIG_FAILED; + } params = ospf_lookup_if_params(ifp, addr); if ((params) == NULL) return CMD_SUCCESS;