X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=apps%2Fasn1pars.c;h=0d6607071fe69b0bc62ffb66a60215344b3a6093;hp=5f8ba5e730337468e78466548928e585b536040d;hb=9f9ab1dc667186c533454c87f70295fcb67b4e8a;hpb=1c3e4a366022c043ae87ff9715905e97582bf649 diff --git a/apps/asn1pars.c b/apps/asn1pars.c index 5f8ba5e730..0d6607071f 100644 --- a/apps/asn1pars.c +++ b/apps/asn1pars.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -/* A nice addition from Dr Stephen Henson to +/* A nice addition from Dr Stephen Henson to * add the -strparse option which parses nested binary structures */ @@ -94,8 +94,9 @@ 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; + STACK_OF(OPENSSL_STRING) *osk=NULL; ASN1_TYPE *at=NULL; informat=FORMAT_PEM; @@ -112,7 +113,7 @@ int MAIN(int argc, char **argv) prog=argv[0]; argc--; argv++; - if ((osk=sk_new_null()) == NULL) + if ((osk=sk_OPENSSL_STRING_new_null()) == NULL) { BIO_printf(bio_err,"Memory allocation failure\n"); goto end; @@ -168,7 +169,7 @@ int MAIN(int argc, char **argv) else if (strcmp(*argv,"-strparse") == 0) { if (--argc < 1) goto bad; - sk_push(osk,*(++argv)); + sk_OPENSSL_STRING_push(osk,*(++argv)); } else if (strcmp(*argv,"-genstr") == 0) { @@ -195,7 +196,7 @@ int MAIN(int argc, char **argv) bad: BIO_printf(bio_err,"%s [options] value.asn1_string->data; tmplen=at->value.asn1_string->length; @@ -333,7 +345,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"); @@ -358,7 +378,7 @@ end: ERR_print_errors(bio_err); if (buf != NULL) BUF_MEM_free(buf); if (at != NULL) ASN1_TYPE_free(at); - if (osk != NULL) sk_free(osk); + if (osk != NULL) sk_OPENSSL_STRING_free(osk); OBJ_cleanup(); apps_shutdown(); OPENSSL_EXIT(ret); @@ -388,6 +408,7 @@ static int do_generate(BIO *bio, char *genstr, char *genconf, BUF_MEM *buf) atyp = ASN1_generate_nconf(genstr, cnf); NCONF_free(cnf); + cnf = NULL; if (!atyp) return -1;