Skip to contentSkip to conversation

Fix CTLV three-byte tag parsing.

PATCH In review Andrzej Zaborowski 3 participants 5 messages Apr 22, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Fix CTLV three-byte tag parsing.

---
 src/simutil.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
src/simutil.c +6 -6
index 9fb111f..822938c 100644
@@ -210,7 +210,7 @@ void comprehension_tlv_iter_init(struct comprehension_tlv_iter *iter,
 	iter->data = 0;
 }
 
-/* Comprehension TLVs defined in Section 7 of ETSI TS 102.220 */
+/* Comprehension TLVs defined in Section 7 of ETSI TS 101.220 */
 gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 {
 	const unsigned char *pdu = iter->pdu + iter->pos;
@@ -230,18 +230,18 @@ gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 		return FALSE;
 
 	/*
-	 * ETSI TS 102.220, Section 7.1.1.2
+	 * ETSI TS 101.220, Section 7.1.1.2
 	 * 
 	 * If byte 1 of the tag is equal to 0x7F, then the tag is encoded
-	 * on the following two bytes, with bit 8 of the 2nd byte of the tag
-	 * being the CR flag.
+	 * on the following two bytes, with bit 8 of the 1st byte of the tag
+	 * as the most significant bit.
 	 */
-	if (tag == 0x7F) {
+	if (tag == 0x7F && !cr) {
 		if ((pdu + 2) > end)
 			return FALSE;
 
 		cr = bit_field(pdu[0], 7, 1);
-		tag = ((pdu[0] & 0x7f) << 7) | pdu[1];
+		tag = ((pdu[0] & 0x7f) << 8) | pdu[1];
 
 		if (tag < 0x0001 || tag > 0x7fff)
 			return FALSE;
Signature · 1 line
1.6.1
#2 lore raw

PATCH 1/1 Fix CTLV three-byte tag parsing.

In reply to Denis Kenzior
---
 src/simutil.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
src/simutil.c +6 -6
index 31b21c7..f994455 100644
@@ -210,7 +210,7 @@ void comprehension_tlv_iter_init(struct comprehension_tlv_iter *iter,
 	iter->data = 0;
 }
 
-/* Comprehension TLVs defined in Section 7 of ETSI TS 102.220 */
+/* Comprehension TLVs defined in Section 7 of ETSI TS 101.220 */
 gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 {
 	const unsigned char *pdu = iter->pdu + iter->pos;
@@ -222,15 +222,15 @@ gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 	if (pdu == end)
 		return FALSE;
 
+	if (*pdu == 0x00 || *pdu == 0xFF || *pdu == 0x80)
+		return FALSE;
+
 	cr = bit_field(*pdu, 7, 1);
 	tag = bit_field(*pdu, 0, 7);
 	pdu++;
 
-	if (tag == 0x00 || tag == 0xFF || tag == 0x80)
-		return FALSE;
-
 	/*
-	 * ETSI TS 102.220, Section 7.1.1.2
+	 * ETSI TS 101.220, Section 7.1.1.2
 	 * 
 	 * If byte 1 of the tag is equal to 0x7F, then the tag is encoded
 	 * on the following two bytes, with bit 8 of the 2nd byte of the tag
@@ -241,7 +241,7 @@ gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 			return FALSE;
 
 		cr = bit_field(pdu[0], 7, 1);
-		tag = ((pdu[0] & 0x7f) << 7) | pdu[1];
+		tag = ((pdu[0] & 0x7f) << 8) | pdu[1];
 
 		if (tag < 0x0001 || tag > 0x7fff)
 			return FALSE;
Signature · 1 line
1.6.1
#4 lore raw
In reply to Andrzej Zaborowski
Quoted 6 lines · Andrzej Zaborowski

        * If byte 1 of the tag is equal to 0x7F, then the tag is encoded
-        * on the following two bytes, with bit 8 of the 2nd byte of the tag
-        * being the CR flag.
+        * on the following two bytes, with bit 8 of the 1st byte of the tag
+        * as the most significant bit.
        */

I noticed my comment change is wrong, it should probably say "bit 8 of the 1st byte of the tag being the CR flag" (1st referring to the first of the last two bytes).

Best regards

From 97dd0f7de6c2b2762cfd5dd18973d56e693b8bbf Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Thu, 22 Apr 2010 01:15:56 +0200
Subject: [PATCH 1/3] Fix CTLV three-byte tag parsing.

---
 src/simutil.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
src/simutil.c +6 -6
index 9fb111f..822938c 100644
@@ -210,7 +210,7 @@ void comprehension_tlv_iter_init(struct comprehension_tlv_iter *iter,
 	iter->data = 0;
 }
 
-/* Comprehension TLVs defined in Section 7 of ETSI TS 102.220 */
+/* Comprehension TLVs defined in Section 7 of ETSI TS 101.220 */
 gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 {
 	const unsigned char *pdu = iter->pdu + iter->pos;
@@ -230,18 +230,18 @@ gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 		return FALSE;
 
 	/*
-	 * ETSI TS 102.220, Section 7.1.1.2
+	 * ETSI TS 101.220, Section 7.1.1.2
 	 * 
 	 * If byte 1 of the tag is equal to 0x7F, then the tag is encoded
-	 * on the following two bytes, with bit 8 of the 2nd byte of the tag
-	 * being the CR flag.
+	 * on the following two bytes, with bit 8 of the 1st byte of the tag
+	 * being the CR flag.
 	 */
-	if (tag == 0x7F) {
+	if (tag == 0x7F && !cr) {
 		if ((pdu + 2) > end)
 			return FALSE;
 
 		cr = bit_field(pdu[0], 7, 1);
-		tag = ((pdu[0] & 0x7f) << 7) | pdu[1];
+		tag = ((pdu[0] & 0x7f) << 8) | pdu[1];
 
 		if (tag < 0x0001 || tag > 0x7fff)
 			return FALSE;
Signature · 1 line
1.6.1
#1 lore raw
In reply to Andrzej Zaborowski

Hi Andrew,

Quoted 19 lines
---
 src/simutil.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
src/simutil.c +1 -1
index 9fb111f..822938c 100644
@@ -210,7 +210,7 @@ void comprehension_tlv_iter_init(struct
 comprehension_tlv_iter *iter, iter->data = 0;
 }
 
-/* Comprehension TLVs defined in Section 7 of ETSI TS 102.220 */
+/* Comprehension TLVs defined in Section 7 of ETSI TS 101.220 */
 gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter)
 {
 	const unsigned char *pdu = iter->pdu + iter->pos;
@@ -230,18 +230,18 @@ gboolean comprehension_tlv_iter_next(struct
 comprehension_tlv_iter *iter) return FALSE;

src/simutil.c gboolean comprehension_tlv_iter_next(struct · line 237

Quoted 10 lines
src/simutil.c +3 -3
 
 	/*
-	 * ETSI TS 102.220, Section 7.1.1.2
+	 * ETSI TS 101.220, Section 7.1.1.2
 	 *
 	 * If byte 1 of the tag is equal to 0x7F, then the tag is encoded
-	 * on the following two bytes, with bit 8 of the 2nd byte of the tag
-	 * being the CR flag.
+	 * on the following two bytes, with bit 8 of the 1st byte of the tag
+	 * as the most significant bit.

Please keep the comment about the CR flag, I think that is useful.

src/simutil.c gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter) · line 239

Quoted 3 lines
src/simutil.c +1 -1
 	 */
-	if (tag == 0x7F) {
+	if (tag == 0x7F && !cr) {

This isn't actually necessary. However, the statement:

        if (tag == 0x00 || tag == 0xFF || tag == 0x80)
                return FALSE;

Actually needs to be moved up and tag changed to *pdu.

src/simutil.c gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter) · line 247

Quoted 10 lines
src/simutil.c +1 -1
 		if ((pdu + 2) > end)
 			return FALSE;
 
 		cr = bit_field(pdu[0], 7, 1);
-		tag = ((pdu[0] & 0x7f) << 7) | pdu[1];
+		tag = ((pdu[0] & 0x7f) << 8) | pdu[1];
 
 		if (tag < 0x0001 || tag > 0x7fff)
 			return FALSE;

Can you resubmit the patch with these changes?

Thanks,
-Denis