Blame SOURCES/openssl-1.0.1e-cve-2015-0287.patch

96beb5
diff -up openssl-1.0.1e/crypto/asn1/tasn_dec.c.item-reuse openssl-1.0.1e/crypto/asn1/tasn_dec.c
96beb5
--- openssl-1.0.1e/crypto/asn1/tasn_dec.c.item-reuse	2013-02-11 16:26:04.000000000 +0100
96beb5
+++ openssl-1.0.1e/crypto/asn1/tasn_dec.c	2015-03-19 15:46:51.097022616 +0100
96beb5
@@ -310,9 +310,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval,
96beb5
 		case ASN1_ITYPE_CHOICE:
96beb5
 		if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
96beb5
 				goto auxerr;
96beb5
-
96beb5
-		/* Allocate structure */
96beb5
-		if (!*pval && !ASN1_item_ex_new(pval, it))
96beb5
+		if (*pval)
96beb5
+			{
96beb5
+			/* Free up and zero CHOICE value if initialised */
96beb5
+			i = asn1_get_choice_selector(pval, it);
96beb5
+			if ((i >= 0) && (i < it->tcount))
96beb5
+				{
96beb5
+				tt = it->templates + i;
96beb5
+				pchptr = asn1_get_field_ptr(pval, tt);
96beb5
+				ASN1_template_free(pchptr, tt);
96beb5
+				asn1_set_choice_selector(pval, -1, it);
96beb5
+				}
96beb5
+			}
96beb5
+		else if (!ASN1_item_ex_new(pval, it))
96beb5
 			{
96beb5
 			ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
96beb5
 						ERR_R_NESTED_ASN1_ERROR);
96beb5
@@ -407,6 +417,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval,
96beb5
 		if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
96beb5
 				goto auxerr;
96beb5
 
96beb5
+		/* Free up and zero any ADB found */
96beb5
+		for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
96beb5
+			{
96beb5
+			if (tt->flags & ASN1_TFLG_ADB_MASK)
96beb5
+				{
96beb5
+				const ASN1_TEMPLATE *seqtt;
96beb5
+				ASN1_VALUE **pseqval;
96beb5
+				seqtt = asn1_do_adb(pval, tt, 1);
96beb5
+				pseqval = asn1_get_field_ptr(pval, seqtt);
96beb5
+				ASN1_template_free(pseqval, seqtt);
96beb5
+				}
96beb5
+			}
96beb5
+
96beb5
 		/* Get each field entry */
96beb5
 		for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
96beb5
 			{