dexter has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-msc/+/43237?usp=email )


Change subject: sgs_iface: clean up code in function decode_mme_name
......................................................................

sgs_iface: clean up code in function decode_mme_name

The function decode_mme_name is a bit hard to read and also has
some minor problems we can optimize.

- do not call TLVP_LEN each time we need the length of the
  TLV IE. Call it once and keep the value in a variable
- mme_name_enc holds the value part of the TLV IE, we can
  use this variable instead of calling TLVP_VAL all all
  the time.
- When we have copied the value part of the TLV IE using
  memset, let's ensure that the string is terminated.

Related: OS#7058
Change-Id: I9aec8300f15264b68ac8e7805e93e621b12cafb2
---
M src/libmsc/sgs_iface.c
1 file changed, 5 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/37/43237/1

diff --git a/src/libmsc/sgs_iface.c b/src/libmsc/sgs_iface.c
index dd39816..aa0ccad 100644
--- a/src/libmsc/sgs_iface.c
+++ b/src/libmsc/sgs_iface.c
@@ -163,6 +163,7 @@
 static int decode_mme_name(char *mme_name, size_t mme_name_len, const struct 
tlv_parsed *tp)
 {
        const uint8_t *mme_name_enc = TLVP_VAL_MINLEN(tp, SGSAP_IE_MME_NAME, 
SGS_MME_NAME_LEN);
+       size_t mme_name_enc_len = TLVP_LEN(tp, SGSAP_IE_MME_NAME);
        struct osmo_gummei gummei;

        if (!mme_name_enc)
@@ -170,17 +171,18 @@

        /* do not accept over-long SGSAP_IE_MME_NAME IEs which would exceed the 
length
         * of the output buffer. */
-       if (TLVP_LEN(tp, SGSAP_IE_MME_NAME) > mme_name_len - 1)
+       if (mme_name_enc_len > mme_name_len - 1)
                return -EINVAL;

        /* some implementations use FDQN format violating TS 29.118 9.3.14 */
        if (!osmo_parse_mme_domain(&gummei, (const char *) mme_name_enc)) {
-               memcpy(mme_name, mme_name_enc, TLVP_LEN(tp, SGSAP_IE_MME_NAME));
+               memcpy(mme_name, mme_name_enc, mme_name_enc_len);
+               mme_name[mme_name_enc_len] = '\0';
                return 0;
        }

        /* decode the MME name from DNS labels to string */
-       osmo_apn_to_str(mme_name, TLVP_VAL(tp, SGSAP_IE_MME_NAME), TLVP_LEN(tp, 
SGSAP_IE_MME_NAME));
+       osmo_apn_to_str(mme_name, mme_name_enc, mme_name_enc_len);

        /* try to parse the MME name into a GUMMEI as a test for the format */
        if (osmo_parse_mme_domain(&gummei, mme_name) < 0)

--
To view, visit https://gerrit.osmocom.org/c/osmo-msc/+/43237?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Change-Id: I9aec8300f15264b68ac8e7805e93e621b12cafb2
Gerrit-Change-Number: 43237
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <[email protected]>

Reply via email to