From 58c0b0a6f7ceb512d433c840f79bc1cdada43adb Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 24 Oct 2022 17:36:13 +0200 Subject: [PATCH] mgw: rx_rtp(): reorder checks and handlings First validate the origin of the message, then later the content of the message and finally execute whatever triggers are necessary. This way contents from unknown senders are not even parsed or acted upon, avoiding useless potential harm. Change-Id: I011a6d7d705768c32a35cec5cd7169725a21a670 --- src/libosmo-mgcp/mgcp_network.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 26f34757c..432c2b175 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -1514,7 +1514,9 @@ static int rx_rtp(struct msgb *msg) LOG_CONN_RTP(conn_src, LOGL_DEBUG, "rx_rtp(%u bytes)\n", msgb_length(msg)); - mgcp_conn_watchdog_kick(conn_src->conn); + /* Check if the origin of the RTP packet seems plausible */ + if (!trunk->rtp_accept_all && check_rtp_origin(conn_src, from_addr)) + return -1; /* If AMR is configured for the ingress connection and conversion of the * framing mode (octet-aligned vs. bandwith-efficient) is explicitly @@ -1534,9 +1536,7 @@ static int rx_rtp(struct msgb *msg) } } - /* Check if the origin of the RTP packet seems plausible */ - if (!trunk->rtp_accept_all && check_rtp_origin(conn_src, from_addr)) - return -1; + mgcp_conn_watchdog_kick(conn_src->conn); /* Execute endpoint specific implementation that handles the * dispatching of the RTP data */