[Asterisk-cvs] libpri pri_facility.c, 1.13, 1.14 pri_facility.h, 1.7, 1.8

mattf at lists.digium.com mattf at lists.digium.com
Thu Jun 2 16:55:29 CDT 2005


Update of /usr/cvsroot/libpri
In directory mongoose.digium.com:/tmp/cvs-serv3300

Modified Files:
	pri_facility.c pri_facility.h 
Log Message:
More fixes for indefinite length in the ASN.1 parsing routines


Index: pri_facility.c
===================================================================
RCS file: /usr/cvsroot/libpri/pri_facility.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- pri_facility.c	23 May 2005 15:06:33 -0000	1.13
+++ pri_facility.c	2 Jun 2005 20:58:32 -0000	1.14
@@ -272,7 +272,7 @@
 			return -1;
 		value->ton = ton;
 
-		return res + 2;
+		return res + 3;
 
 	} while(0);
 	return -1;
@@ -335,6 +335,7 @@
 			pri_message(pri, "!! Unknown Party number component received 0x%X\n", comp->type);
 			return -1;
 		}
+		ASN1_FIXUP_LEN(comp, res);
 		NEXT_COMPONENT(comp, i);
 		if(i < len)
 			pri_message(pri, "!! not all information is handled from Address component\n");
@@ -348,6 +349,7 @@
 static int rose_presented_number_unscreened_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
 {
 	int i = 0;
+	int size = 0;
 	struct rose_component *comp = NULL;
 	unsigned char *vdata = data;
 
@@ -362,7 +364,9 @@
 		switch(comp->type) {
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0):		/* [0] presentationAllowedNumber */
 			value->pres = PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
-			return rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
+			size = rose_address_decode(pri, call, comp->data, comp->len, value);
+			ASN1_FIXUP_LEN(comp, size);
+			return size + 2;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1):		/* [1] IMPLICIT presentationRestricted */
 			if (comp->len != 0) { /* must be NULL */
 				pri_error(pri, "!! Invalid PresentationRestricted component received (len != 0)\n");
@@ -379,7 +383,9 @@
 			return 2;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3):		/* [3] presentationRestrictedNumber */
 			value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
-			return rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
+			size = rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
+			ASN1_FIXUP_LEN(comp, size);
+			return size + 2;
 		default:
 			pri_message(pri, "Invalid PresentedNumberUnscreened component 0x%X\n", comp->type);
 		}
@@ -431,6 +437,7 @@
 			case ASN1_TAG_1:		/* divertingnr: presentednumberunscreened */
 				res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &divertingnr);
 				/* TODO: Fix indefinite length form hacks */
+				ASN1_FIXUP_LEN(comp, res);
 				comp->len = res;
 				if (res < 0)
 					return -1;
@@ -443,6 +450,7 @@
 				res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &originalcallednr);
 				if (res < 0)
 					return -1;
+				ASN1_FIXUP_LEN(comp, res);
 				comp->len = res;
 				if (pri->debug & PRI_DEBUG_APDU) {
 					pri_message(pri, "    Received originalcallednr '%s'\n", originalcallednr.partyaddress);
@@ -450,12 +458,20 @@
 				}
 				break;
 			case ASN1_TAG_3:
-				comp->len = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname));
+				res = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname));
+				if (res < 0)
+					return -1;
+				ASN1_FIXUP_LEN(comp, res);
+				comp->len = res;
 				if (pri->debug & PRI_DEBUG_APDU)
 					pri_message(pri, "    Received RedirectingName '%s'\n", redirectingname);
 				break;
 			case ASN1_TAG_4:
-				comp->len = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname));
+				res = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname));
+				if (res < 0)
+					return -1;
+				ASN1_FIXUP_LEN(comp, res);
+				comp->len = res;
 				if (pri->debug & PRI_DEBUG_APDU)
 					pri_message(pri, "    Received Originally Called Name '%s'\n", origcalledname);
 				break;
@@ -494,7 +510,7 @@
 
 	return -1;
 }
-
+				
 static int rose_diverting_leg_information2_encode(struct pri *pri, q931_call *call)
 {
 	int i = 0, j, compsp = 0;

Index: pri_facility.h
===================================================================
RCS file: /usr/cvsroot/libpri/pri_facility.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pri_facility.h	2 Jun 2005 15:55:49 -0000	1.7
+++ pri_facility.h	2 Jun 2005 20:58:32 -0000	1.8
@@ -180,6 +180,12 @@
 			(variable) = ((variable) << 8) | (component)->data[comp_idx]; \
 	} while (0)
 
+#define ASN1_FIXUP_LEN(component, size) \
+	do { \
+		if ((component)->len == ASN1_LEN_INDEF) \
+			size += 2; \
+	} while (0)
+
 #define ASN1_ADD_SIMPLE(component, comptype, ptr, idx) \
 	do { \
 		(component) = (struct rose_component *)&((ptr)[(idx)]); \




More information about the svn-commits mailing list