From 1b8a1dc00a9965674a93d72f5f042deea546b94a Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 4 May 2018 16:46:47 +0200 Subject: add error handling to osmo_gsup_configure_wildcard_apn() Follow-up to I83d9ef2868bbb01e3f1ddb7920fe735aca172b15 as requested in code review. Change-Id: Ifcee1e0d275741c1172b208600851861adb13238 --- src/gsup_server.c | 11 +++++++---- src/gsup_server.h | 4 ++-- src/hlr.c | 6 +++++- src/luop.c | 7 ++++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/gsup_server.c b/src/gsup_server.c index 03a6f56..07d4feb 100644 --- a/src/gsup_server.c +++ b/src/gsup_server.c @@ -337,15 +337,16 @@ void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups) /* Set GSUP message's pdp_infos[0] to a wildcard APN. * Use the provided apn_buf to store the produced APN data. This must remain valid until - * osmo_gsup_encode() is done. */ -void osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, - uint8_t *apn_buf, size_t apn_buf_size) + * osmo_gsup_encode() is done. Return 0 if an entry was added, -ENOMEM if the provided buffer is too + * small. */ +int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, + uint8_t *apn_buf, size_t apn_buf_size) { int l; l = osmo_apn_from_str(apn_buf, apn_buf_size, "*"); if (l <= 0) - return; + return -ENOMEM; gsup->pdp_infos[0].apn_enc = apn_buf; gsup->pdp_infos[0].apn_enc_len = l; @@ -353,4 +354,6 @@ void osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, gsup->num_pdp_infos = 1; /* FIXME: use real value: */ gsup->pdp_infos[0].context_id = 1; + + return 0; } diff --git a/src/gsup_server.h b/src/gsup_server.h index b52b783..66c1a9c 100644 --- a/src/gsup_server.h +++ b/src/gsup_server.h @@ -53,5 +53,5 @@ struct osmo_gsup_server *osmo_gsup_server_create(void *ctx, void osmo_gsup_server_destroy(struct osmo_gsup_server *gsups); -void osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, - uint8_t *apn_buf, size_t apn_buf_size); +int osmo_gsup_configure_wildcard_apn(struct osmo_gsup_message *gsup, + uint8_t *apn_buf, size_t apn_buf_size); diff --git a/src/hlr.c b/src/hlr.c index cab34f0..1c72f45 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -98,7 +98,11 @@ osmo_hlr_subscriber_update_notify(struct hlr_subscriber *subscr) /* FIXME: PDP infos - use more fine-grained access control instead of wildcard APN */ - osmo_gsup_configure_wildcard_apn(&gsup, apn, sizeof(apn)); + if (osmo_gsup_configure_wildcard_apn(&gsup, apn, sizeof(apn))) { + LOGP(DMAIN, LOGL_ERROR, "%s: Error: cannot encode wildcard APN\n", + subscr->imsi); + continue; + } } else if (co->supports_cs) { gsup.cn_domain = OSMO_GSUP_CN_DOMAIN_CS; } else { diff --git a/src/luop.c b/src/luop.c index edf4c51..db7b3c9 100644 --- a/src/luop.c +++ b/src/luop.c @@ -242,7 +242,12 @@ void lu_op_tx_insert_subscr_data(struct lu_operation *luop) if (luop->is_ps) { /* FIXME: PDP infos - use more fine-grained access control instead of wildcard APN */ - osmo_gsup_configure_wildcard_apn(&gsup, apn, sizeof(apn)); + if (osmo_gsup_configure_wildcard_apn(&gsup, apn, sizeof(apn))) { + LOGP(DMAIN, LOGL_ERROR, "%s: Error: cannot encode wildcard APN\n", + luop->subscr.imsi); + lu_op_tx_error(luop, GMM_CAUSE_PROTO_ERR_UNSPEC); + return; + } } /* Send ISD to new VLR/SGSN */ -- cgit v1.2.3