nat: Verify that the endpoint from the assignment command exists

Make sure that the MSC endpoint exists on the NAT, otherwise
we end up trying to free this endpoint when the SCCP connection
is taken down and will corrupt our memory. This issue started
to pop up as we have reduced the number of endpoints to 60
to allow transcoding on them.
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c
index 750975f..cb6360b 100644
--- a/openbsc/src/nat/bsc_mgcp_utils.c
+++ b/openbsc/src/nat/bsc_mgcp_utils.c
@@ -75,7 +75,7 @@
 	uint16_t cic;
 	uint8_t timeslot;
 	uint8_t multiplex;
-	int endp;
+	unsigned int endp;
 
 	if (!msg->l3h) {
 		LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n");
@@ -100,6 +100,13 @@
 
 	endp = mgcp_timeslot_to_endpoint(multiplex, timeslot);
 
+	if (endp >= con->bsc->nat->mgcp_cfg->number_endpoints) {
+		LOGP(DNAT, LOGL_ERROR,
+			"MSC attempted to assign bad endpoint 0x%x\n",
+			endp);
+		return -1;
+	}
+
 	/* find stale connections using that endpoint */
 	llist_for_each_entry(mcon, &con->bsc->nat->sccp_connections, list_entry) {
 		if (mcon->msc_endp == endp) {