From 75b3cba5fcd43f372d3486616f526e5bef9e8cc2 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Tue, 1 Sep 2020 20:17:47 +0200 Subject: Fail on invalid IP addresses passed to IPACC MDCX IPACC protocol supports only IPv4 addresses, so make sure if an IPv6 address (or whatever malformed address) is caught is not sent without noticing. Prior to this patch, faulty addresses would be sent over the wire as 255.255.255.255 (-1 returned from inet_addr()). Change-Id: Iee84e8b40cdede1cacd8e8a9e26dda0d85383ec8 --- src/osmo-bsc/lchan_rtp_fsm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/osmo-bsc/lchan_rtp_fsm.c b/src/osmo-bsc/lchan_rtp_fsm.c index 1fe545286..1dd31b134 100644 --- a/src/osmo-bsc/lchan_rtp_fsm.c +++ b/src/osmo-bsc/lchan_rtp_fsm.c @@ -330,6 +330,7 @@ static void lchan_rtp_fsm_wait_ipacc_mdcx_ack_onenter(struct osmo_fsm_inst *fi, int rc; struct gsm_lchan *lchan = lchan_rtp_fi_lchan(fi); const struct mgcp_conn_peer *mgw_rtp; + struct in_addr sin; if (lchan->release.requested) { lchan_rtp_fail("Release requested while activating"); @@ -344,8 +345,13 @@ static void lchan_rtp_fsm_wait_ipacc_mdcx_ack_onenter(struct osmo_fsm_inst *fi, return; } - /* Other RTP settings were already setup in lchan_rtp_fsm_wait_ipacc_crcx_ack_onenter() */ - lchan->abis_ip.connect_ip = ntohl(inet_addr(mgw_rtp->addr)); + /* Other RTP settings were already set up in lchan_rtp_fsm_wait_ipacc_crcx_ack_onenter() */ + if (inet_pton(AF_INET, mgw_rtp->addr, &sin) != 1) { + /* Only IPv4 addresses are supported in IPACC */ + lchan_rtp_fail("Invalid remote IPv4 address %s", mgw_rtp->addr); + return; + } + lchan->abis_ip.connect_ip = ntohl(sin.s_addr); lchan->abis_ip.connect_port = mgw_rtp->port; /* send-recv */ -- cgit v1.2.3