Commit 03996c19 authored by Richard Levitte's avatar Richard Levitte
Browse files

asn1_item_embed_new(): don't free an embedded item



The previous change with this intention didn't quite do it.  An
embedded item must not be freed itself, but might potentially contain
non-embedded elements, which must be freed.

So instead of calling ASN1_item_ex_free(), where we can't pass the
embed flag, we call asn1_item_embed_free() directly.

This changes asn1_item_embed_free() from being a static function to
being a private non-static function.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
Reviewed-by: default avatarBernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/4579)
parent 4ce8bebc
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,7 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
                  const ASN1_ITEM *it);
                  const ASN1_ITEM *it);


void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed);
void asn1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed);
void asn1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed);
void asn1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
void asn1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);


+1 −5
Original line number Original line Diff line number Diff line
@@ -13,9 +13,6 @@
#include <openssl/objects.h>
#include <openssl/objects.h>
#include "asn1_locl.h"
#include "asn1_locl.h"


static void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
                                 int embed);

/* Free up an ASN1 structure */
/* Free up an ASN1 structure */


void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
@@ -28,8 +25,7 @@ void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
    asn1_item_embed_free(pval, it, 0);
    asn1_item_embed_free(pval, it, 0);
}
}


static void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it,
void asn1_item_embed_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
                                 int embed)
{
{
    const ASN1_TEMPLATE *tt = NULL, *seqtt;
    const ASN1_TEMPLATE *tt = NULL, *seqtt;
    const ASN1_EXTERN_FUNCS *ef;
    const ASN1_EXTERN_FUNCS *ef;
+2 −4
Original line number Original line Diff line number Diff line
@@ -142,8 +142,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
    return 1;
    return 1;


 memerr2:
 memerr2:
    if (!embed)
    asn1_item_embed_free(pval, it, embed);
        ASN1_item_ex_free(pval, it);
 memerr:
 memerr:
    ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ERR_R_MALLOC_FAILURE);
    ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ERR_R_MALLOC_FAILURE);
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
@@ -152,8 +151,7 @@ int asn1_item_embed_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int embed)
    return 0;
    return 0;


 auxerr2:
 auxerr2:
    if (!embed)
    asn1_item_embed_free(pval, it, embed);
        ASN1_item_ex_free(pval, it);
 auxerr:
 auxerr:
    ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ASN1_R_AUX_ERROR);
    ASN1err(ASN1_F_ASN1_ITEM_EMBED_NEW, ASN1_R_AUX_ERROR);
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
#ifndef OPENSSL_NO_CRYPTO_MDEBUG