Fix indefinite length encoding so EOC correctly updates
[openssl.git] / crypto / asn1 / tasn_enc.c
index 5ce38e192023db7035364b8a61f85a2a5a360394..2e806550749c2ea3eb83774eb60977bf18d35fa2 100644 (file)
@@ -494,7 +494,10 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const A
        if(out) {
                if(usetag) ASN1_put_object(out, ndef, len, tag, aclass);
                asn1_ex_i2c(pval, *out, &utype, it);
        if(out) {
                if(usetag) ASN1_put_object(out, ndef, len, tag, aclass);
                asn1_ex_i2c(pval, *out, &utype, it);
-               *out += len;
+               if (ndef)
+                       ASN1_put_eoc(out);
+               else
+                       *out += len;
        }
 
        if(usetag) return ASN1_object_size(ndef, len, tag);
        }
 
        if(usetag) return ASN1_object_size(ndef, len, tag);
@@ -598,7 +601,6 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_
                                {
                                strtmp->data = cout;
                                strtmp->length = 0;
                                {
                                strtmp->data = cout;
                                strtmp->length = 0;
-                               ASN1_put_eoc(&cout);
                                }
                        /* Special return code */
                        return -2;
                                }
                        /* Special return code */
                        return -2;