Max has submitted this change and it was merged.

Change subject: GSUP: change osmo_gsup_encode() return type
......................................................................


GSUP: change osmo_gsup_encode() return type

* match return type of osmo_gsup_encode() with osmo_gsup_decode() to allow
  propagating error to caller
* check return value of osmo_gsup_encode() in GSUP test
* return errors instead of braking app with aseert

Change-Id: Idaa1deecb6d9e15329bd51867b4f6a03357461f0
Related: OS#2864
---
M include/osmocom/gsm/gsup.h
M src/gsm/gsup.c
M tests/gsup/gsup_test.c
3 files changed, 13 insertions(+), 6 deletions(-)

Approvals:
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/gsm/gsup.h b/include/osmocom/gsm/gsup.h
index 5cfe1ec..1a8a3b2 100644
--- a/include/osmocom/gsm/gsup.h
+++ b/include/osmocom/gsm/gsup.h
@@ -179,6 +179,6 @@
 
 int osmo_gsup_decode(const uint8_t *data, size_t data_len,
                     struct osmo_gsup_message *gsup_msg);
-void osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message 
*gsup_msg);
+int osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message 
*gsup_msg);
 
 /*! @} */
diff --git a/src/gsm/gsup.c b/src/gsm/gsup.c
index eb829f7..b6ac56d 100644
--- a/src/gsm/gsup.c
+++ b/src/gsm/gsup.c
@@ -475,8 +475,9 @@
 /*! Encode a GSUP message
  *  \param[out] msg message buffer to which encoded message is written
  *  \param[in] gsup_msg \ref osmo_gsup_message data to be encoded
+ *  \returns 0 on success; negative otherwise
  */
-void osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message 
*gsup_msg)
+int osmo_gsup_encode(struct msgb *msg, const struct osmo_gsup_message 
*gsup_msg)
 {
        uint8_t u8;
        int idx;
@@ -484,14 +485,16 @@
        size_t bcd_len;
 
        /* generic part */
-       OSMO_ASSERT(gsup_msg->message_type);
+       if(!gsup_msg->message_type)
+               return -ENOMEM;
+
        msgb_v_put(msg, gsup_msg->message_type);
 
        bcd_len = gsm48_encode_bcd_number(bcd_buf, sizeof(bcd_buf), 0,
                                          gsup_msg->imsi);
 
-       OSMO_ASSERT(bcd_len > 1);
-       OSMO_ASSERT(bcd_len <= sizeof(bcd_buf));
+       if (bcd_len <= 0 || bcd_len > sizeof(bcd_buf))
+               return -EINVAL;
 
        /* Note that gsm48_encode_bcd_number puts the length into the first
         * octet. Since msgb_tlv_put will add this length byte, we'll have to
@@ -560,6 +563,8 @@
                msgb_tlv_put(msg, OSMO_GSUP_CHARG_CHAR_IE,
                                gsup_msg->pdp_charg_enc_len, 
gsup_msg->pdp_charg_enc);
        }
+
+       return 0;
 }
 
 /*! @} */
diff --git a/tests/gsup/gsup_test.c b/tests/gsup/gsup_test.c
index eddcc92..b55f1d9 100644
--- a/tests/gsup/gsup_test.c
+++ b/tests/gsup/gsup_test.c
@@ -220,7 +220,9 @@
                if (rc < 0)
                        passed = false;
 
-               osmo_gsup_encode(msg, &gm);
+               rc = osmo_gsup_encode(msg, &gm);
+               if (rc < 0)
+                       passed = false;
 
                fprintf(stderr, "  generated message: %s\n", msgb_hexdump(msg));
                fprintf(stderr, "  original message:  %s\n", 
osmo_hexdump(t->data, t->data_len));

-- 
To view, visit https://gerrit.osmocom.org/6009
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idaa1deecb6d9e15329bd51867b4f6a03357461f0
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Stefan Sperling <ssperl...@sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilira...@gmail.com>

Reply via email to