add error handling to osmo_gsup_configure_wildcard_apn()

Follow-up to I83d9ef2868bbb01e3f1ddb7920fe735aca172b15 as requested in code review.

Change-Id: Ifcee1e0d275741c1172b208600851861adb13238
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 @@
 
 /* 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 @@
 	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 @@
 
 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 @@
 
 			/* 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 @@
 	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 */