From de17bd5d7f8286d8b1f0a04a3f8f5782033f5ebd Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Tue, 15 Sep 2015 15:54:19 +0100 Subject: New ASN.1 embed macro. New ASN.1 macro ASN1_EMBED. This is the same as ASN1_SIMPLE except the structure is not allocated: it is part of the parent. That is instead of FOO *x; it must be: FOO x; This reduces memory fragmentation and make it impossible to accidentally set a mandatory field to NULL. This currently only works for SEQUENCE and since it is equivalent to ASN1_SIMPLE it cannot be tagged, OPTIONAL, SET OF or SEQUENCE OF. Reviewed-by: Rich Salz --- crypto/asn1/tasn_dec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'crypto/asn1/tasn_dec.c') diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c index 732b4253d1..939ee205be 100644 --- a/crypto/asn1/tasn_dec.c +++ b/crypto/asn1/tasn_dec.c @@ -524,6 +524,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, { int flags, aclass; int ret; + ASN1_VALUE *tval; const unsigned char *p, *q; if (!val) return 0; @@ -533,6 +534,15 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, p = *in; q = p; + /* + * If field is embedded then val needs fixing so it is a pointer to + * a pointer to a field. + */ + if (tt->flags & ASN1_TFLG_EMBED) { + tval = (ASN1_VALUE *)val; + val = &tval; + } + if (flags & ASN1_TFLG_SK_MASK) { /* SET OF, SEQUENCE OF */ int sktag, skaclass; -- cgit v1.2.3