cbc: Don't crash if peer->remote_host is NULL

As the peer->remote_host is initially NULL when creating a CBC peer,
the code should tolerate this.  The situation arises in two cases:

* if a peer is created by VTY but without any subequent 'remote-ip'
  statement
* if a peer is auto-created by 'unknown-peers accept'

Closes: OS#5506
Change-Id: I455e61f379f042680cdd2600a08d57a1ea22897c
This commit is contained in:
Harald Welte 2022-05-06 10:42:13 +02:00
parent 4db977919c
commit 8b12076f97
2 changed files with 6 additions and 2 deletions

View File

@ -99,6 +99,8 @@ struct cbc_peer *cbc_peer_by_addr_proto(const char *remote_host, uint16_t remote
struct cbc_peer *peer;
llist_for_each_entry(peer, &g_cbc->peers, list) {
if (!peer->remote_host)
continue;
if (!strcasecmp(remote_host, peer->remote_host)) {
if (peer->remote_port == -1)
return peer;

View File

@ -48,7 +48,8 @@ static void dump_one_cbc_peer(struct vty *vty, const struct cbc_peer *peer)
}
vty_out(vty, "|%-20s| %-15s| %-5d| %-6s| %-20s|%s",
peer->name ? peer->name : "<unnamed>", peer->remote_host, peer->remote_port,
peer->name ? peer->name : "<unnamed>",
peer->remote_host ? peer->remote_host : "<unset>", peer->remote_port,
get_value_string(cbc_peer_proto_name, peer->proto), state, VTY_NEWLINE);
}
@ -488,7 +489,8 @@ static void write_one_peer(struct vty *vty, struct cbc_peer *peer)
vty_out(vty, " no remote-port%s", VTY_NEWLINE);
else
vty_out(vty, " remote-port %d%s", peer->remote_port, VTY_NEWLINE);
vty_out(vty, " remote-ip %s%s", peer->remote_host, VTY_NEWLINE);
if (peer->remote_host)
vty_out(vty, " remote-ip %s%s", peer->remote_host, VTY_NEWLINE);
}
static int config_write_peer(struct vty *vty)