Constify d2i, s2i, c2i and r2i functions and other associated
[openssl.git] / apps / asn1pars.c
index 5f8ba5e730337468e78466548928e585b536040d..305db1590359068f9e7360cbcd43a21faf5d94b6 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;
@@ -317,7 +318,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)
                                {
@@ -333,7 +335,15 @@ bad:
                num=tmplen;
                }
 
-       if (length == 0) length=(unsigned int)num;
+       if (offset >= num)
+               {
+               BIO_printf(bio_err, "Error: offset too large\n");
+               goto end;
+               }
+
+       num -= offset;
+
+       if ((length == 0) || ((long)length > num)) length=(unsigned int)num;
        if(derout) {
                if(BIO_write(derout, str + offset, length) != (int)length) {
                        BIO_printf(bio_err, "Error writing output\n");