diff options
author | Fabio Fiorina <fiorinaf@gnutls.org> | 2003-02-25 22:07:40 +0000 |
---|---|---|
committer | Fabio Fiorina <fiorinaf@gnutls.org> | 2003-02-25 22:07:40 +0000 |
commit | 0b694f3b2ae54571462ab7b7f1b0ed4ca73d10b1 (patch) | |
tree | cf994329907b490d814732b1af7149d3f5aeb35e /src | |
parent | 53449a4560f3dbded7f48b2929427fa9be4dde54 (diff) | |
download | libtasn1-0b694f3b2ae54571462ab7b7f1b0ed4ca73d10b1.tar.gz libtasn1-0b694f3b2ae54571462ab7b7f1b0ed4ca73d10b1.tar.bz2 libtasn1-0b694f3b2ae54571462ab7b7f1b0ed4ca73d10b1.zip |
add vector length check
Diffstat (limited to 'src')
-rw-r--r-- | src/CertificateExample.c | 16 | ||||
-rw-r--r-- | src/CrlExample.c | 11 | ||||
-rw-r--r-- | src/asn1Coding.c | 1 |
3 files changed, 24 insertions, 4 deletions
diff --git a/src/CertificateExample.c b/src/CertificateExample.c index 2f3bf96..fc60cf9 100644 --- a/src/CertificateExample.c +++ b/src/CertificateExample.c @@ -186,6 +186,9 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) ASN1_TYPE param=ASN1_TYPE_EMPTY; ASN1_TYPE constr=ASN1_TYPE_EMPTY; char errorDescription[MAX_ERROR_DESCRIPTION_SIZE]; + int max_len; + + max_len=*der_len; result=asn1_create_element(cert_def,"PKIX1Implicit88.Certificate",&cert1); @@ -222,6 +225,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) result=asn1_create_element(cert_def,"PKIX1Implicit88.X520countryName", &value); result=asn1_write_value(value,"","US",2); + *der_len = max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -237,6 +241,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) &value); result=asn1_write_value(value,"","printableString",1); result=asn1_write_value(value,"printableString","gov",3); + *der_len = max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -253,6 +258,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value); result=asn1_write_value(value,"","printableString",1); result=asn1_write_value(value,"printableString","nist",4); + *der_len = max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -279,6 +285,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) result=asn1_create_element(cert_def,"PKIX1Implicit88.X520countryName", &value); result=asn1_write_value(value,"","US",2); + *der_len = max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -294,6 +301,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) &value); result=asn1_write_value(value,"","printableString",1); result=asn1_write_value(value,"printableString","gov",3); + *der_len = max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -309,6 +317,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value); result=asn1_write_value(value,"","printableString",1); result=asn1_write_value(value,"printableString","nist",4); + *der_len = max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -325,6 +334,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) result=asn1_write_value(param,"q",str2,20); str2="\xd4\x38"; /* only an example */ result=asn1_write_value(param,"g",str2,128); + *der_len = max_len; result=asn1_der_coding(param,"",der,der_len,errorDescription); asn1_delete_structure(¶m); result=asn1_write_value(cert1,"tbsCertificate.subjectPublicKeyInfo.algorithm.parameters",der,*der_len); @@ -347,6 +357,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) result=asn1_create_element(cert_def,"PKIX1Implicit88.BasicConstraints",&constr); result=asn1_write_value(constr,"cA","TRUE",1); result=asn1_write_value(constr,"pathLenConstraint",NULL,0); + *der_len = max_len; result=asn1_der_coding(constr,"",der,der_len,errorDescription); result=asn1_delete_structure(&constr); result=asn1_write_value(cert1,"tbsCertificate.extensions.?LAST.extnValue",der,*der_len); @@ -370,6 +381,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) /* signature */ + *der_len = max_len; result=asn1_der_coding(cert1,"tbsCertificate",der,der_len ,errorDescription); if(result!=ASN1_SUCCESS){ @@ -384,7 +396,7 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len) asn1_visit_tree(cert1,""); printf("-----------------\n"); */ - + *der_len = max_len; result=asn1_der_coding(cert1,"",der,der_len,errorDescription); if(result!=ASN1_SUCCESS){ printf("\n'certificate' encoding creation: ERROR\n"); @@ -501,7 +513,7 @@ main(int argc,char *argv[]) asn1_visit_tree(PKIX1Implicit88,"PKIX1Implicit88"); printf("-----------------\n"); */ - + der_len=1024; create_certificate(PKIX1Implicit88,der,&der_len); get_certificate(PKIX1Implicit88,der,der_len); diff --git a/src/CrlExample.c b/src/CrlExample.c index 1aafbd7..2eba8c9 100644 --- a/src/CrlExample.c +++ b/src/CrlExample.c @@ -194,6 +194,9 @@ create_CRL(node_asn *cert_def, unsigned char *der,int *der_len) ASN1_TYPE crl=ASN1_TYPE_EMPTY; ASN1_TYPE value=ASN1_TYPE_EMPTY; char errorDescription[MAX_ERROR_DESCRIPTION_SIZE]; + int max_len; + + max_len=*der_len; result=asn1_create_element(cert_def,"PKIX1Implicit88.CertificateList",&crl); @@ -226,6 +229,7 @@ create_CRL(node_asn *cert_def, unsigned char *der,int *der_len) result=asn1_create_element(cert_def,"PKIX1Implicit88.X520countryName", &value); result=asn1_write_value(value,"","US",2); + *der_len=max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); @@ -242,6 +246,7 @@ create_CRL(node_asn *cert_def, unsigned char *der,int *der_len) &value); result=asn1_write_value(value,"","printableString",1); result=asn1_write_value(value,"printableString","gov",3); + *der_len=max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -257,6 +262,7 @@ create_CRL(node_asn *cert_def, unsigned char *der,int *der_len) result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value); result=asn1_write_value(value,"","printableString",1); result=asn1_write_value(value,"printableString","nist",4); + *der_len=max_len; result=asn1_der_coding(value,"",der,der_len,errorDescription); asn1_delete_structure(&value); result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len); @@ -298,6 +304,7 @@ create_CRL(node_asn *cert_def, unsigned char *der,int *der_len) result=asn1_write_value(crl,"signatureAlgorithm.parameters",NULL,0); /* NO OPTION */ /* signature */ + *der_len=max_len; result=asn1_der_coding(crl,"tbsCertList",der,der_len,errorDescription); if(result!=ASN1_SUCCESS){ printf("\n'tbsCertList' encoding creation: ERROR\n"); @@ -313,7 +320,7 @@ create_CRL(node_asn *cert_def, unsigned char *der,int *der_len) asn1_visit_tree(crl,""); printf("-----------------\n"); */ - + *der_len=max_len; result=asn1_der_coding(crl,"",der,der_len,errorDescription); if(result!=ASN1_SUCCESS){ printf("\n'crl1' encoding creation: ERROR\n"); @@ -424,7 +431,7 @@ main(int argc,char *argv[]) asn1_visit_tree(cert_def,"PKIX1Implicit88"); printf("-----------------\n"); */ - + der_len=1024; create_CRL(PKIX1Implicit88,der,&der_len); diff --git a/src/asn1Coding.c b/src/asn1Coding.c index 2688332..0480c77 100644 --- a/src/asn1Coding.c +++ b/src/asn1Coding.c @@ -286,6 +286,7 @@ main(int argc,char *argv[]) printf("\n"); asn1_print_structure(stdout,structure,"",ASN1_PRINT_NAME_TYPE_VALUE); + der_len=1024; asn1_result=asn1_der_coding(structure,"",der,&der_len, errorDescription); printf("\nCoding: %s\n\n",libtasn1_strerror(asn1_result)); |