/*
- * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
#include <openssl/err.h>
#include <openssl/asn1t.h>
#include <string.h>
-#include "asn1_locl.h"
+#include "asn1_local.h"
+
+DEFINE_STACK_OF(ASN1_VALUE)
static int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
int embed);
else
asn1_cb = 0;
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_push(it->sname ? it->sname : "asn1_item_embed_new");
-#endif
-
switch (it->itype) {
case ASN1_ITYPE_EXTERN:
if (!i)
goto auxerr;
if (i == 2) {
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_pop();
-#endif
return 1;
}
}
if (!i)
goto auxerr;
if (i == 2) {
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_pop();
-#endif
return 1;
}
}
goto memerr;
}
/* 0 : init. lock */
- if (asn1_do_lock(pval, 0, it) < 0)
- goto memerr2;
+ if (asn1_do_lock(pval, 0, it) < 0) {
+ if (!embed) {
+ OPENSSL_free(*pval);
+ *pval = NULL;
+ }
+ goto memerr;
+ }
asn1_enc_init(pval, it);
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
pseqval = asn1_get_field_ptr(pval, tt);
goto auxerr2;
break;
}
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_pop();
-#endif
return 1;
memerr2:
- if (!embed)
- ASN1_item_ex_free(pval, it);
+ asn1_item_embed_free(pval, it, embed);
memerr:
ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ERR_R_MALLOC_FAILURE);
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_pop();
-#endif
return 0;
auxerr2:
- if (!embed)
- ASN1_item_ex_free(pval, it);
+ asn1_item_embed_free(pval, it, embed);
auxerr:
ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ASN1_R_AUX_ERROR);
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_pop();
-#endif
return 0;
}
*pval = NULL;
return 1;
}
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_push(tt->field_name
- ? tt->field_name : "asn1_template_new");
-#endif
/* If SET OF or SEQUENCE OF, its a STACK */
if (tt->flags & ASN1_TFLG_SK_MASK) {
STACK_OF(ASN1_VALUE) *skval;
/* Otherwise pass it back to the item routine */
ret = asn1_item_embed_new(pval, it, embed);
done:
-#ifndef OPENSSL_NO_CRYPTO_MDEBUG
- OPENSSL_mem_debug_pop();
-#endif
return ret;
}
return 1;
case V_ASN1_ANY:
- typ = OPENSSL_malloc(sizeof(*typ));
- if (typ == NULL)
+ if ((typ = OPENSSL_malloc(sizeof(*typ))) == NULL) {
+ ASN1err(ASN1_F_ASN1_PRIMITIVE_NEW, ERR_R_MALLOC_FAILURE);
return 0;
+ }
typ->value.ptr = NULL;
typ->type = -1;
*pval = (ASN1_VALUE *)typ;