GSUP: check osmo_gsup_encode() result

Check and handle gracefully any error which might appear in
osmo_gsup_encode() - mark corresponding functions with
warn_unused_result attribute to make sure this failure is always checked
against.

Change-Id: I4551212011fb0bd898c020a183756ed7a9afb9e5
Related: OS#2864
diff --git a/src/libvlr/vlr.c b/src/libvlr/vlr.c
index 96627ed..f73eeb4 100644
--- a/src/libvlr/vlr.c
+++ b/src/libvlr/vlr.c
@@ -130,7 +130,11 @@
 {
 	struct msgb *msg = gsup_client_msgb_alloc();
 
-	osmo_gsup_encode(msg, gsup_msg);
+	int rc = osmo_gsup_encode(msg, gsup_msg);
+	if (rc < 0) {
+		LOGP(DVLR, LOGL_ERROR, "GSUP encoding failure: %s\n", strerror(-rc));
+		return rc;
+	}
 
 	if (!vlr->gsup_client) {
 		LOGP(DVLR, LOGL_NOTICE, "GSUP link is down, cannot "
@@ -498,8 +502,10 @@
 				   struct osmo_gsup_message *gsup_msg)
 {
 	if (OSMO_GSUP_IS_MSGT_REQUEST(gsup_msg->message_type)) {
-		vlr_tx_gsup_error_reply(vlr, gsup_msg,
-					GMM_CAUSE_IMSI_UNKNOWN);
+		int rc = vlr_tx_gsup_error_reply(vlr, gsup_msg, GMM_CAUSE_IMSI_UNKNOWN);
+		if (rc < 0)
+			LOGP(DVLR, LOGL_ERROR, "Failed to send error reply for IMSI %s\n", gsup_msg->imsi);
+
 		LOGP(DVLR, LOGL_NOTICE,
 		     "Unknown IMSI %s, discarding GSUP request "
 		     "of type 0x%02x\n",
@@ -775,7 +781,7 @@
 					struct osmo_gsup_message *gsup_msg)
 {
 	struct osmo_gsup_message gsup_reply = {0};
-	int is_update_procedure = !gsup_msg->cancel_type ||
+	int rc, is_update_procedure = !gsup_msg->cancel_type ||
 		gsup_msg->cancel_type == OSMO_GSUP_CANCEL_TYPE_UPDATE;
 
 	LOGVSUBP(LOGL_INFO, vsub, "Cancelling MS subscriber (%s)\n",
@@ -783,11 +789,11 @@
 		 "update procedure" : "subscription withdraw");
 
 	gsup_reply.message_type = OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT;
-	vlr_subscr_tx_gsup_message(vsub, &gsup_reply);
+	rc = vlr_subscr_tx_gsup_message(vsub, &gsup_reply);
 
 	vlr_subscr_cancel(vsub, gsup_msg->cause);
 
-	return 0;
+	return rc;
 }
 
 /* Incoming handler for GSUP from HLR.
@@ -812,9 +818,11 @@
 
 	if (!gsup.imsi[0]) {
 		LOGP(DVLR, LOGL_ERROR, "Missing IMSI in GSUP message\n");
-		if (OSMO_GSUP_IS_MSGT_REQUEST(gsup.message_type))
-			vlr_tx_gsup_error_reply(vlr, &gsup,
-						GMM_CAUSE_INV_MAND_INFO);
+		if (OSMO_GSUP_IS_MSGT_REQUEST(gsup.message_type)) {
+			rc = vlr_tx_gsup_error_reply(vlr, &gsup, GMM_CAUSE_INV_MAND_INFO);
+			if (rc < 0)
+				LOGP(DVLR, LOGL_ERROR, "Failed to send error reply for IMSI %s\n", gsup.imsi);
+		}
 		rc = -GMM_CAUSE_INV_MAND_INFO;
 		goto msgb_free_and_return;
 	}