bgpd: fix compiler warnings in nbr cmd

Addressed the gcc-10 buffer overflow warnings.
Put a sanity check of not using prefix for
neighbor update-source with interface option.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
This commit is contained in:
Chirag Shah 2020-11-06 11:06:58 -08:00
parent 6403fc8725
commit 555c8ab7ad
2 changed files with 30 additions and 29 deletions

View File

@ -3033,9 +3033,17 @@ int bgp_neighbors_neighbor_update_source_interface_modify(
struct bgp *bgp;
const char *peer_str, *source_str;
struct peer *peer;
struct prefix p;
switch (args->event) {
case NB_EV_VALIDATE:
source_str = yang_dnode_get_string(args->dnode, NULL);
if (str2prefix(source_str, &p)) {
snprintf(args->errmsg, args->errmsg_len,
"Invalid update-source, remove prefix length");
return NB_ERR_VALIDATION;
}
break;
case NB_EV_PREPARE:
case NB_EV_ABORT:
return NB_OK;
@ -5071,9 +5079,17 @@ int bgp_neighbors_unnumbered_neighbor_update_source_interface_modify(
struct bgp *bgp;
const char *peer_str, *source_str;
struct peer *peer;
struct prefix p;
switch (args->event) {
case NB_EV_VALIDATE:
source_str = yang_dnode_get_string(args->dnode, NULL);
if (str2prefix(source_str, &p)) {
snprintf(args->errmsg, args->errmsg_len,
"Invalid update-source, remove prefix length");
return NB_ERR_VALIDATION;
}
break;
case NB_EV_PREPARE:
case NB_EV_ABORT:
return NB_OK;
@ -6963,9 +6979,17 @@ int bgp_peer_groups_peer_group_update_source_interface_modify(
struct bgp *bgp;
const char *peer_str, *source_str;
struct peer *peer;
struct prefix p;
switch (args->event) {
case NB_EV_VALIDATE:
source_str = yang_dnode_get_string(args->dnode, NULL);
if (str2prefix(source_str, &p)) {
snprintf(args->errmsg, args->errmsg_len,
"Invalid update-source, remove prefix length");
return NB_ERR_VALIDATION;
}
break;
case NB_EV_PREPARE:
case NB_EV_ABORT:
return NB_OK;

View File

@ -4795,27 +4795,18 @@ DEFUN_YANG(neighbor_activate,
{
int idx_peer = 1;
char base_xpath[XPATH_MAXLEN];
char abs_xpath[XPATH_MAXLEN];
char nbr_xpath[XPATH_MAXLEN];
char af_xpath[XPATH_MAXLEN];
afi_t afi = bgp_node_afi(vty);
safi_t safi = bgp_node_safi(vty);
snprintf(af_xpath, sizeof(af_xpath), FRR_BGP_AF_XPATH,
yang_afi_safi_value2identity(afi, safi));
if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, nbr_xpath,
sizeof(nbr_xpath), af_xpath)
if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
sizeof(base_xpath), af_xpath)
< 0)
return CMD_WARNING_CONFIG_FAILED;
snprintf(base_xpath, sizeof(base_xpath), "%s%s", VTY_CURR_XPATH,
nbr_xpath + 1);
snprintf(abs_xpath, sizeof(abs_xpath), "%s%s/enabled", VTY_CURR_XPATH,
nbr_xpath + 1);
nb_cli_enqueue_change(vty, abs_xpath, NB_OP_MODIFY, "true");
nb_cli_enqueue_change(vty, "./enabled", NB_OP_MODIFY, "true");
return nb_cli_apply_changes(vty, base_xpath);
}
@ -6944,7 +6935,6 @@ DEFUN_YANG (neighbor_update_source,
< 0)
return CMD_WARNING_CONFIG_FAILED;
// NOTE: Check source_str prefix address
if (str2sockunion(argv[idx_peer_2]->arg, &su) == 0)
nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_MODIFY,
argv[idx_peer_2]->arg);
@ -6965,28 +6955,15 @@ DEFUN_YANG (no_neighbor_update_source,
{
int idx_peer = 2;
char base_xpath[XPATH_MAXLEN];
char abs_xpath_ip[XPATH_MAXLEN];
char abs_xpath_intf[XPATH_MAXLEN];
if (peer_and_group_lookup_nb(vty, argv[idx_peer]->arg, base_xpath,
sizeof(base_xpath), NULL)
< 0)
return CMD_WARNING_CONFIG_FAILED;
snprintf(abs_xpath_ip, sizeof(abs_xpath_ip), "%s%s/update-source/ip",
VTY_CURR_XPATH, base_xpath + 1);
snprintf(abs_xpath_intf, sizeof(abs_xpath_intf),
"%s%s/update-source/interface", VTY_CURR_XPATH,
base_xpath + 1);
if (yang_dnode_exists(vty->candidate_config->dnode, abs_xpath_ip)) {
nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY,
NULL);
} else if (yang_dnode_exists(vty->candidate_config->dnode,
abs_xpath_intf)) {
nb_cli_enqueue_change(vty, "./update-source/interface",
NB_OP_DESTROY, NULL);
}
nb_cli_enqueue_change(vty, "./update-source/ip", NB_OP_DESTROY, NULL);
nb_cli_enqueue_change(vty, "./update-source/interface", NB_OP_DESTROY,
NULL);
return nb_cli_apply_changes(vty, base_xpath);
}