embed support for CHOICE type
authorDr. Stephen Henson <steve@openssl.org>
Tue, 6 Oct 2015 21:53:48 +0000 (22:53 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Sun, 11 Oct 2015 19:33:56 +0000 (20:33 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/asn1/tasn_fre.c
crypto/asn1/tasn_new.c

index bd955d98489859aec1ce93bf226ce8321282c5d5..1e778858ac13879e5877438554e3b430387d8734 100644 (file)
@@ -125,8 +125,10 @@ static void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
         }
         if (asn1_cb)
             asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
-        OPENSSL_free(*pval);
-        *pval = NULL;
+        if (embed == 0) {
+            OPENSSL_free(*pval);
+            *pval = NULL;
+        }
         break;
 
     case ASN1_ITYPE_EXTERN:
index 294912c188e76209a6da6811558182ad26063cdd..13db8676fc876e7a1085cc3fbc0cf72f5d414897 100644 (file)
@@ -142,9 +142,13 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
                 return 1;
             }
         }
-        *pval = OPENSSL_zalloc(it->size);
-        if (!*pval)
-            goto memerr;
+        if (embed) {
+            memset(*pval, 0, it->size);
+        } else {
+            *pval = OPENSSL_zalloc(it->size);
+            if (!*pval)
+                goto memerr;
+        }
         asn1_set_choice_selector(pval, -1, it);
         if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
             goto auxerr;