From: Matt Caswell Date: Thu, 12 Nov 2020 14:55:31 +0000 (+0000) Subject: Complain if we are attempting to encode with an invalid ASN.1 template X-Git-Tag: openssl-3.0.0-alpha10~123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3db2c9f3e5fb9f649ebb4a55918398756310af43;p=thirdparty%2Fopenssl.git Complain if we are attempting to encode with an invalid ASN.1 template It never makes sense for multi-string or CHOICE types to have implicit tagging. If we have a template that uses the in this way then we should immediately fail. Thanks to David Benjamin from Google for reporting this issue. Reviewed-by: Tomas Mraz --- diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c index 798dc69650e..9d65f294db3 100644 --- a/crypto/asn1/tasn_enc.c +++ b/crypto/asn1/tasn_enc.c @@ -106,9 +106,25 @@ int ASN1_item_ex_i2d(const ASN1_VALUE **pval, unsigned char **out, return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); case ASN1_ITYPE_MSTRING: + /* + * It never makes sense for multi-strings to have implicit tagging, so + * if tag != -1, then this looks like an error in the template. + */ + if (tag != -1) { + ERR_raise(ERR_LIB_ASN1, ASN1_R_BAD_TEMPLATE); + return -1; + } return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); case ASN1_ITYPE_CHOICE: + /* + * It never makes sense for CHOICE types to have implicit tagging, so + * if tag != -1, then this looks like an error in the template. + */ + if (tag != -1) { + ERR_raise(ERR_LIB_ASN1, ASN1_R_BAD_TEMPLATE); + return -1; + } if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) return 0; i = asn1_get_choice_selector_const(pval, it);