1 |
diff -up openssl-fips-0.9.8e/crypto/asn1/tasn_dec.c.item-reuse openssl-fips-0.9.8e/crypto/asn1/tasn_dec.c |
2 |
--- openssl-fips-0.9.8e/crypto/asn1/tasn_dec.c.item-reuse 2015-04-01 12:41:27.000000000 +0200 |
3 |
+++ openssl-fips-0.9.8e/crypto/asn1/tasn_dec.c 2015-04-02 15:06:40.184407040 +0200 |
4 |
@@ -308,9 +308,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, |
5 |
case ASN1_ITYPE_CHOICE: |
6 |
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) |
7 |
goto auxerr; |
8 |
- |
9 |
- /* Allocate structure */ |
10 |
- if (!*pval && !ASN1_item_ex_new(pval, it)) |
11 |
+ if (*pval) |
12 |
+ { |
13 |
+ /* Free up and zero CHOICE value if initialised */ |
14 |
+ i = asn1_get_choice_selector(pval, it); |
15 |
+ if ((i >= 0) && (i < it->tcount)) |
16 |
+ { |
17 |
+ tt = it->templates + i; |
18 |
+ pchptr = asn1_get_field_ptr(pval, tt); |
19 |
+ ASN1_template_free(pchptr, tt); |
20 |
+ asn1_set_choice_selector(pval, -1, it); |
21 |
+ } |
22 |
+ } |
23 |
+ else if (!ASN1_item_ex_new(pval, it)) |
24 |
{ |
25 |
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, |
26 |
ERR_R_NESTED_ASN1_ERROR); |
27 |
@@ -406,6 +416,19 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, |
28 |
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) |
29 |
goto auxerr; |
30 |
|
31 |
+ /* Free up and zero any ADB found */ |
32 |
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) |
33 |
+ { |
34 |
+ if (tt->flags & ASN1_TFLG_ADB_MASK) |
35 |
+ { |
36 |
+ const ASN1_TEMPLATE *seqtt; |
37 |
+ ASN1_VALUE **pseqval; |
38 |
+ seqtt = asn1_do_adb(pval, tt, 1); |
39 |
+ pseqval = asn1_get_field_ptr(pval, seqtt); |
40 |
+ ASN1_template_free(pseqval, seqtt); |
41 |
+ } |
42 |
+ } |
43 |
+ |
44 |
/* Get each field entry */ |
45 |
for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) |
46 |
{ |