laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-cbc/+/28057 )
Change subject: cbc: Don't crash if peer->remote_host is NULL
......................................................................
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
---
M src/cbc_data.c
M src/cbc_vty.c
2 files changed, 6 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-cbc refs/changes/57/28057/1
diff --git a/src/cbc_data.c b/src/cbc_data.c
index d1d20f1..60c0998 100644
--- a/src/cbc_data.c
+++ b/src/cbc_data.c
@@ -99,6 +99,8 @@
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;
diff --git a/src/cbc_vty.c b/src/cbc_vty.c
index f0c34d6..b45fbd4 100644
--- a/src/cbc_vty.c
+++ b/src/cbc_vty.c
@@ -48,7 +48,8 @@
}
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 @@
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)
--
To view, visit
https://gerrit.osmocom.org/c/osmo-cbc/+/28057
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-cbc
Gerrit-Branch: master
Gerrit-Change-Id: I455e61f379f042680cdd2600a08d57a1ea22897c
Gerrit-Change-Number: 28057
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange