projects
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Demo of use of errors in applications.
[openssl.git]
/
apps
/
asn1pars.c
diff --git
a/apps/asn1pars.c
b/apps/asn1pars.c
index 5f8ba5e730337468e78466548928e585b536040d..0d6607071fe69b0bc62ffb66a60215344b3a6093 100644
(file)
--- a/
apps/asn1pars.c
+++ b/
apps/asn1pars.c
@@
-56,7
+56,7
@@
* [including the GNU Public Licence.]
*/
* [including the GNU Public Licence.]
*/
-/* A nice addition from Dr Stephen Henson <s
henson@bigfoot.com
> to
+/* A nice addition from Dr Stephen Henson <s
teve@openssl.org
> to
* add the -strparse option which parses nested binary structures
*/
* 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;
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;
BUF_MEM *buf=NULL;
- STACK *osk=NULL;
+ STACK
_OF(OPENSSL_STRING)
*osk=NULL;
ASN1_TYPE *at=NULL;
informat=FORMAT_PEM;
ASN1_TYPE *at=NULL;
informat=FORMAT_PEM;
@@
-112,7
+113,7
@@
int MAIN(int argc, char **argv)
prog=argv[0];
argc--;
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;
{
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;
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)
{
}
else if (strcmp(*argv,"-genstr") == 0)
{
@@
-195,7
+196,7
@@
int MAIN(int argc, char **argv)
bad:
BIO_printf(bio_err,"%s [options] <infile\n",prog);
BIO_printf(bio_err,"where options are\n");
bad:
BIO_printf(bio_err,"%s [options] <infile\n",prog);
BIO_printf(bio_err,"where options are\n");
- BIO_printf(bio_err," -inform arg input format - one of DER
TXT
PEM\n");
+ BIO_printf(bio_err," -inform arg input format - one of DER PEM\n");
BIO_printf(bio_err," -in arg input file\n");
BIO_printf(bio_err," -out arg output file (output format is always DER\n");
BIO_printf(bio_err," -noout arg don't produce any output\n");
BIO_printf(bio_err," -in arg input file\n");
BIO_printf(bio_err," -out arg output file (output format is always DER\n");
BIO_printf(bio_err," -noout arg don't produce any output\n");
@@
-301,23
+302,25
@@
bad:
/* If any structs to parse go through in sequence */
/* If any structs to parse go through in sequence */
- if (sk_num(osk))
+ if (sk_
OPENSSL_STRING_
num(osk))
{
tmpbuf=(unsigned char *)str;
tmplen=num;
{
tmpbuf=(unsigned char *)str;
tmplen=num;
- for (i=0; i<sk_num(osk); i++)
+ for (i=0; i<sk_
OPENSSL_STRING_
num(osk); i++)
{
ASN1_TYPE *atmp;
{
ASN1_TYPE *atmp;
- j=atoi(sk_value(osk,i));
+ int typ;
+ j=atoi(sk_OPENSSL_STRING_value(osk,i));
if (j == 0)
{
if (j == 0)
{
- BIO_printf(bio_err,"'%s' is an invalid number\n",sk_value(osk,i));
+ BIO_printf(bio_err,"'%s' is an invalid number\n",sk_
OPENSSL_STRING_
value(osk,i));
continue;
}
tmpbuf+=j;
tmplen-=j;
atmp = at;
continue;
}
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)
{
ASN1_TYPE_free(atmp);
if(!at)
{
@@
-325,6
+328,15
@@
bad:
ERR_print_errors(bio_err);
goto end;
}
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;
/* hmm... this is a little evil but it works */
tmpbuf=at->value.asn1_string->data;
tmplen=at->value.asn1_string->length;
@@
-333,7
+345,15
@@
bad:
num=tmplen;
}
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");
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);
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);
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);
atyp = ASN1_generate_nconf(genstr, cnf);
NCONF_free(cnf);
+ cnf = NULL;
if (!atyp)
return -1;
if (!atyp)
return -1;