[PATCH] libosmocore[master]: gsm0480: fix USSD OCTET STRING length

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
Thu Jan 11 17:49:07 UTC 2018


Hello Alexander Chemeris, Jenkins Builder,

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

    https://gerrit.osmocom.org/5712

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

gsm0480: fix USSD OCTET STRING length

According to the GSM 04.80 (version 5.0.0) specification Annex A
"Expanded ASN.1 Module "SS-Protocol", the maximum size of a USSD
OCTET STRING is 160 bytes.

Thus according to ETSI TS 123 038 (version 10.0.0) specification
6.1.2.3 "USSD packing of 7 bit characters", in 160 octets, it's
possible to pack (160 * 8) / 7 = 182.8, that is 182 characters.
The remaining 6 bits are set to zero.

This change defines both mentioned values:

  - MAX_LEN_USSD_OCTET_STRING  160
  - MAX_LEN_USSD_7BIT_STRING   182

keeping the old MAX_LEN_USSD_STRING as is due to compatibility
reasons. Now the new value is used for the gsm0480_ss_request,
while the old one is still used for deprecated
ussd_request structure.

Change-Id: I6dead74f9ecea079752ff2400cdaf7c30187784e
---
M include/osmocom/gsm/gsm0480.h
M src/gsm/gsm0480.c
2 files changed, 24 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/12/5712/4

diff --git a/include/osmocom/gsm/gsm0480.h b/include/osmocom/gsm/gsm0480.h
index 781d8d7..cca09bb 100644
--- a/include/osmocom/gsm/gsm0480.h
+++ b/include/osmocom/gsm/gsm0480.h
@@ -7,7 +7,27 @@
 #include <osmocom/gsm/protocol/gsm_04_08.h>
 #include <osmocom/gsm/protocol/gsm_04_80.h>
 
-#define MAX_LEN_USSD_STRING	31
+/**
+ * According to the GSM 04.80 (version 5.0.0) specification Annex A
+ * "Expanded ASN.1 Module "SS-Protocol", the maximum size of a USSD
+ * OCTET STRING field is 160 bytes.
+ */
+#define MAX_LEN_USSD_OCTET_STRING	160
+
+/**
+ * Thus according to ETSI TS 123 038 (version 10.0.0) specification
+ * 6.1.2.3 "USSD packing of 7 bit characters", in 160 octets, it's
+ * possible to pack (160 * 8) / 7 = 182.8, that is 182 characters.
+ * The remaining 6 bits are set to zero.
+ */
+#define MAX_LEN_USSD_7BIT_STRING	182
+
+/**
+ * DEPRECATED: this definition doesn't follow any specification,
+ * so we only keep it for compatibility reasons. It's strongly
+ * recommended to use correct definitions above.
+ */
+#define MAX_LEN_USSD_STRING		31
 
 /* deprecated */
 struct ussd_request {
@@ -42,7 +62,7 @@
 
 	uint8_t ussd_text_len;
 	uint8_t ussd_text_language;
-	uint8_t ussd_text[MAX_LEN_USSD_STRING + 1];
+	uint8_t ussd_text[MAX_LEN_USSD_OCTET_STRING];
 
 	/*! Parameters of a Interrogate/Activate/DeactivateSS Request */
 	uint8_t ss_code;
diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c
index 9cfe336..4c7352c 100644
--- a/src/gsm/gsm0480.c
+++ b/src/gsm/gsm0480.c
@@ -453,8 +453,8 @@
 			    (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 > MAX_LEN_USSD_STRING)
-					num_chars = MAX_LEN_USSD_STRING;
+				if (num_chars > MAX_LEN_USSD_7BIT_STRING)
+					num_chars = MAX_LEN_USSD_7BIT_STRING;
 
 				num_chars = gsm_7bit_decode_n_ussd((char *)req->ussd_text,
 					sizeof(req->ussd_text), &(uss_req_data[7]), num_chars);

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I6dead74f9ecea079752ff2400cdaf7c30187784e
Gerrit-PatchSet: 4
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: Ivan Kluchnikov <kluchnikovi at gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list