[PATCH] libosmocore[master]: gsm0480: clean up the parse_process_uss_req() code

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Sun Jan 14 12:03:42 UTC 2018


Hello Alexander Chemeris, Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/3375

to look at the new patch set (#9).

gsm0480: clean up the parse_process_uss_req() code

This change reduces the degree of code nesting...

Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
---
M src/gsm/gsm0480.c
1 file changed, 20 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/75/3375/9

diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c
index dcf487a..11c66e9 100644
--- a/src/gsm/gsm0480.c
+++ b/src/gsm/gsm0480.c
@@ -439,33 +439,34 @@
 static int parse_process_uss_req(const uint8_t *uss_req_data, uint16_t length,
 				 struct ss_request *req)
 {
-	int rc = 0;
-	int num_chars;
+	uint8_t num_chars;
 	uint8_t dcs;
-
 
 	/* we need at least that much */
 	if (length < 8)
 		return 0;
 
+	if (uss_req_data[0] != GSM_0480_SEQUENCE_TAG)
+		return 0;
 
-	if (uss_req_data[0] == GSM_0480_SEQUENCE_TAG) {
-		if (uss_req_data[2] == ASN1_OCTET_STRING_TAG) {
-			dcs = uss_req_data[4];
-			if ((dcs == 0x0F) &&
-			    (uss_req_data[5] == ASN1_OCTET_STRING_TAG)) {
-				num_chars = (uss_req_data[6] * 8) / 7;
-				/* Prevent a mobile-originated buffer-overrun! */
-				if (num_chars > GSM0480_USSD_7BIT_STRING_LEN)
-					num_chars = GSM0480_USSD_7BIT_STRING_LEN;
-				gsm_7bit_decode_n_ussd((char *)req->ussd_text,
-							sizeof(req->ussd_text),
-							&(uss_req_data[7]), num_chars);
-				rc = 1;
-			}
-		}
+	/* Both 2th and 5th should be equal to ASN1_OCTET_STRING_TAG */
+	if ((uss_req_data[2] & uss_req_data[5]) != ASN1_OCTET_STRING_TAG)
+		return 0;
+
+	dcs = uss_req_data[4];
+	if (dcs == 0x0F) {
+		num_chars = (uss_req_data[6] * 8) / 7;
+		/* Prevent a mobile-originated buffer-overrun! */
+		if (num_chars > GSM0480_USSD_7BIT_STRING_LEN)
+			num_chars = GSM0480_USSD_7BIT_STRING_LEN;
+
+		gsm_7bit_decode_n_ussd((char *)req->ussd_text,
+			sizeof(req->ussd_text), &(uss_req_data[7]), num_chars);
+
+		return 1;
 	}
-	return rc;
+
+	return 0;
 }
 
 /* Parse the parameters of a Interrogate/Activate/DeactivateSS Request */

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I467f75794c5ac9df75c001245b18bbdfcfaadd88
Gerrit-PatchSet: 9
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Alexander Chemeris <Alexander.Chemeris at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Ivan Kluchnikov <kluchnikovi at gmail.com>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list