aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2018-06-11 20:28:35 +0200
committerHarald Welte <laforge@gnumonks.org>2018-06-11 20:28:35 +0200
commita1d3b048fb7a8047a9854d29067c44a6b0066ee7 (patch)
treeb26dbcd29c3aaf04a83dcb9c01cb68861ce04a5f
parentf83432c25c840bfe088ae5f3d27114b9085ad73e (diff)
Return proper GSUP error in case of too short IMSI
This fixes HLR_Tests.TC_gsup_sai_err_invalid_imsi Change-Id: I4f51abdf44dfc62d7e8792341aad6dafe58923da Closes: OS#3028
-rw-r--r--src/hlr.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/hlr.c b/src/hlr.c
index 4da7b9b..ee19795 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -338,6 +338,29 @@ static int rx_purge_ms_req(struct osmo_gsup_conn *conn,
return osmo_gsup_conn_send(conn, msg_out);
}
+static int gsup_send_err_reply(struct osmo_gsup_conn *conn, const char *imsi,
+ enum osmo_gsup_message_type type_in, uint8_t err_cause)
+{
+ int type_err = osmo_gsup_get_err_msg_type(type_in);
+ struct osmo_gsup_message gsup_reply = {0};
+ struct msgb *msg_out;
+
+ if (type_err < 0) {
+ LOGP(DMAIN, LOGL_ERROR, "unable to determine error response for %s\n",
+ osmo_gsup_message_type_name(type_in));
+ return type_err;
+ }
+
+ OSMO_STRLCPY_ARRAY(gsup_reply.imsi, imsi);
+ gsup_reply.message_type = type_err;
+ gsup_reply.cause = err_cause;
+ msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP ERR response");
+ OSMO_ASSERT(msg_out);
+ osmo_gsup_encode(msg_out, &gsup_reply);
+ LOGP(DMAIN, LOGL_NOTICE, "Tx %s\n", osmo_gsup_message_type_name(type_err));
+ return osmo_gsup_conn_send(conn, msg_out);
+}
+
static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
{
static struct osmo_gsup_message gsup;
@@ -349,6 +372,11 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
return rc;
}
+ /* 3GPP TS 23.003 Section 2.2 clearly states that an IMSI with less than 5
+ * digits is impossible. Even 5 digits is a highly theoretical case */
+ if (strlen(gsup.imsi) < 5)
+ return gsup_send_err_reply(conn, gsup.imsi, gsup.message_type, GMM_CAUSE_INV_MAND_INFO);
+
switch (gsup.message_type) {
/* requests sent to us */
case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST: