Don't try to parse non string types.
[openssl.git] / apps / asn1pars.c
index c28b5ec194dcfb5e55292cf0f24c595f1876e465..f1d8bc8b98b846936b47d0d2d0ef9bceaba5f90d 100644 (file)
@@ -94,6 +94,7 @@ int MAIN(int argc, char **argv)
        char *infile=NULL,*str=NULL,*prog,*oidfile=NULL, *derfile=NULL;
        char *genstr=NULL, *genconf=NULL;
        unsigned char *tmpbuf;
+       const unsigned char *ctmpbuf;
        BUF_MEM *buf=NULL;
        STACK *osk=NULL;
        ASN1_TYPE *at=NULL;
@@ -308,6 +309,7 @@ bad:
                for (i=0; i<sk_num(osk); i++)
                        {
                        ASN1_TYPE *atmp;
+                       int typ;
                        j=atoi(sk_value(osk,i));
                        if (j == 0)
                                {
@@ -317,7 +319,8 @@ bad:
                        tmpbuf+=j;
                        tmplen-=j;
                        atmp = at;
-                       at = d2i_ASN1_TYPE(NULL,&tmpbuf,tmplen);
+                       ctmpbuf = tmpbuf;
+                       at = d2i_ASN1_TYPE(NULL,&ctmpbuf,tmplen);
                        ASN1_TYPE_free(atmp);
                        if(!at)
                                {
@@ -325,6 +328,15 @@ bad:
                                ERR_print_errors(bio_err);
                                goto end;
                                }
+                       typ = ASN1_TYPE_get(at);
+                       if ((typ == V_ASN1_OBJECT)
+                               || (typ == V_ASN1_NULL))
+                               {
+                               BIO_printf(bio_err, "Can't parse %s type\n",
+                                       typ == V_ASN1_NULL ? "NULL" : "OBJECT");
+                               ERR_print_errors(bio_err);
+                               goto end;
+                               }
                        /* hmm... this is a little evil but it works */
                        tmpbuf=at->value.asn1_string->data;
                        tmplen=at->value.asn1_string->length;