[MERGED] osmo-mgw[master]: mcgp_client: mgcp_msg_gen(): add checks to verify params

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Dec 12 17:59:08 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: mcgp_client: mgcp_msg_gen(): add checks to verify params
......................................................................


mcgp_client: mgcp_msg_gen(): add checks to verify params

mgcp_msg_gen() does not check the contents of the prameters that
are handed over with the struct. This may lead to invalid mgcp
messages sent to the MGW, which can be difficult to debug.

Add some additional checks to make a possible problem
noticeable in an early stage.

- verify that the endpoint is not a nullstring
- verify that the connection id is not a nullstring
- verify that the ip-address is not a nullstring
- verify that the port number is a value greater 0

Change-Id: I15c464c4bcdf6e524f68acc62f44186dd7ad19a7
---
M src/libosmo-mgcp-client/mgcp_client.c
1 file changed, 28 insertions(+), 2 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 2f3d0d1..1c35aa9 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -789,8 +789,15 @@
 	}
 
 	/* Add endpoint name */
-	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_ENDPOINT)
+	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_ENDPOINT) {
+		if (strlen(mgcp_msg->endpoint) <= 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Empty endpoint name, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
 		rc += msgb_printf(msg, " %s", mgcp_msg->endpoint);
+	}
 
 	/* Add protocol version */
 	rc += msgb_printf(msg, " MGCP 1.0\r\n");
@@ -800,8 +807,15 @@
 		rc += msgb_printf(msg, "C: %x\r\n", mgcp_msg->call_id);
 
 	/* Add connection id */
-	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_CONN_ID)
+	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_CONN_ID) {
+		if (strlen(mgcp_msg->conn_id) <= 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Empty connection id, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
 		rc += msgb_printf(msg, "I: %s\r\n", mgcp_msg->conn_id);
+	}
 
 	/* Add local connection options */
 	if (mgcp_msg->verb == MGCP_VERB_CRCX)
@@ -816,6 +830,18 @@
 	/* Add RTP address and port (SDP) */
 	if (mgcp_msg->presence & MGCP_MSG_PRESENCE_AUDIO_IP
 	    && mgcp_msg->presence & MGCP_MSG_PRESENCE_AUDIO_PORT) {
+		if (mgcp_msg->audio_port == 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Invalid port number, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
+		if (strlen(mgcp_msg->audio_ip) <= 0) {
+			LOGP(DLMGCP, LOGL_ERROR,
+			     "Empty ip address, can not generate MGCP message\n");
+			msgb_free(msg);
+			return NULL;
+		}
 		rc += msgb_printf(msg, "\r\n");
 		rc += msgb_printf(msg, "c=IN IP4 %s\r\n", mgcp_msg->audio_ip);
 		rc +=

-- 
To view, visit https://gerrit.osmocom.org/5268
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I15c464c4bcdf6e524f68acc62f44186dd7ad19a7
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list