diff options
author | Ben Laurie <ben@openssl.org> | 2008-06-04 11:01:43 +0000 |
---|---|---|
committer | Ben Laurie <ben@openssl.org> | 2008-06-04 11:01:43 +0000 |
commit | 5ce278a77bd7d23bcf965cfa37afb7b937c1a17d (patch) | |
tree | a69f3fe7e5a7e222cdd1e9314e671ffbcf79fc27 /crypto/asn1 | |
parent | 37cf49a3df4b0094c5d335008705518e93b2dad2 (diff) |
More type-checking.
Diffstat (limited to 'crypto/asn1')
-rw-r--r-- | crypto/asn1/a_set.c | 42 | ||||
-rw-r--r-- | crypto/asn1/ameth_lib.c | 18 | ||||
-rw-r--r-- | crypto/asn1/asn1.h | 18 | ||||
-rw-r--r-- | crypto/asn1/asn_pack.c | 8 | ||||
-rw-r--r-- | crypto/asn1/tasn_dec.c | 10 | ||||
-rw-r--r-- | crypto/asn1/tasn_prn.c | 7 | ||||
-rw-r--r-- | crypto/asn1/x_name.c | 71 |
7 files changed, 94 insertions, 80 deletions
diff --git a/crypto/asn1/a_set.c b/crypto/asn1/a_set.c index 958558c204..2405ce1ec2 100644 --- a/crypto/asn1/a_set.c +++ b/crypto/asn1/a_set.c @@ -85,8 +85,9 @@ static int SetBlobCmp(const void *elem1, const void *elem2 ) } /* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */ -int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag, - int ex_class, int is_set) +int i2d_ASN1_SET(STACK_OF(BLOCK) *a, unsigned char **pp, + i2d_of_void *i2d, int ex_tag, int ex_class, + int is_set) { int ret=0,r; int i; @@ -96,8 +97,8 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag, int totSize; if (a == NULL) return(0); - for (i=sk_num(a)-1; i>=0; i--) - ret+=i2d(sk_value(a,i),NULL); + for (i=sk_BLOCK_num(a)-1; i>=0; i--) + ret+=i2d(sk_BLOCK_value(a,i),NULL); r=ASN1_object_size(1,ret,ex_tag); if (pp == NULL) return(r); @@ -108,10 +109,10 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag, /* And then again by Ben */ /* And again by Steve */ - if(!is_set || (sk_num(a) < 2)) + if(!is_set || (sk_BLOCK_num(a) < 2)) { - for (i=0; i<sk_num(a); i++) - i2d(sk_value(a,i),&p); + for (i=0; i<sk_BLOCK_num(a); i++) + i2d(sk_BLOCK_value(a,i),&p); *pp=p; return(r); @@ -119,17 +120,17 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag, pStart = p; /* Catch the beg of Setblobs*/ /* In this array we will store the SET blobs */ - rgSetBlob = (MYBLOB *)OPENSSL_malloc(sk_num(a) * sizeof(MYBLOB)); + rgSetBlob = OPENSSL_malloc(sk_BLOCK_num(a) * sizeof(MYBLOB)); if (rgSetBlob == NULL) { ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE); return(0); } - for (i=0; i<sk_num(a); i++) + for (i=0; i<sk_BLOCK_num(a); i++) { rgSetBlob[i].pbData = p; /* catch each set encode blob */ - i2d(sk_value(a,i),&p); + i2d(sk_BLOCK_value(a,i),&p); rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this SetBlob */ @@ -139,7 +140,7 @@ SetBlob /* Now we have to sort the blobs. I am using a simple algo. *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/ - qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp); + qsort( rgSetBlob, sk_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp); if (!(pTempMem = OPENSSL_malloc(totSize))) { ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE); @@ -148,7 +149,7 @@ SetBlob /* Copy to temp mem */ p = pTempMem; - for(i=0; i<sk_num(a); ++i) + for(i=0; i<sk_BLOCK_num(a); ++i) { memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData); p += rgSetBlob[i].cbData; @@ -162,16 +163,17 @@ SetBlob return(r); } -STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, - d2i_of_void *d2i, void (*free_func)(void *), int ex_tag, - int ex_class) +STACK_OF(BLOCK) *d2i_ASN1_SET(STACK_OF(BLOCK) **a, const unsigned char **pp, + long length, d2i_of_void *d2i, + void (*free_func)(BLOCK), int ex_tag, + int ex_class) { ASN1_const_CTX c; - STACK *ret=NULL; + STACK_OF(BLOCK) *ret=NULL; if ((a == NULL) || ((*a) == NULL)) { - if ((ret=sk_new_null()) == NULL) + if ((ret=sk_BLOCK_new_null()) == NULL) { ASN1err(ASN1_F_D2I_ASN1_SET,ERR_R_MALLOC_FAILURE); goto err; @@ -219,7 +221,7 @@ STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, asn1_add_error(*pp,(int)(c.q- *pp)); goto err; } - if (!sk_push(ret,s)) goto err; + if (!sk_BLOCK_push(ret,s)) goto err; } if (a != NULL) (*a)=ret; *pp=c.p; @@ -228,9 +230,9 @@ err: if ((ret != NULL) && ((a == NULL) || (*a != ret))) { if (free_func != NULL) - sk_pop_free(ret,free_func); + sk_BLOCK_pop_free(ret,free_func); else - sk_free(ret); + sk_BLOCK_free(ret); } return(NULL); } diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index cfaef87555..d155791324 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -94,7 +94,8 @@ static const EVP_PKEY_ASN1_METHOD *standard_methods[] = }; typedef int sk_cmp_fn_type(const char * const *a, const char * const *b); -static STACK *app_methods = NULL; +DECLARE_STACK_OF(EVP_PKEY_ASN1_METHOD); +static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL; @@ -121,7 +122,7 @@ int EVP_PKEY_asn1_get_count(void) { int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); if (app_methods) - num += sk_num(app_methods); + num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); return num; } @@ -133,7 +134,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) if (idx < num) return standard_methods[idx]; idx -= num; - return (const EVP_PKEY_ASN1_METHOD *)sk_value(app_methods, idx); + return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); } static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) @@ -143,10 +144,9 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) if (app_methods) { int idx; - idx = sk_find(app_methods, (char *)&tmp); + idx = sk_EVP_PKEY_ASN1_METHOD_find(app_methods, &tmp); if (idx >= 0) - return (EVP_PKEY_ASN1_METHOD *) - sk_value(app_methods, idx); + return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); } ret = (EVP_PKEY_ASN1_METHOD **) OBJ_bsearch((char *)&t, (char *)standard_methods, @@ -234,13 +234,13 @@ int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth) { if (app_methods == NULL) { - app_methods = sk_new((sk_cmp_fn_type *)ameth_cmp); + app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp); if (!app_methods) return 0; } - if (!sk_push(app_methods, (char *)ameth)) + if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth)) return 0; - sk_sort(app_methods); + sk_EVP_PKEY_ASN1_METHOD_sort(app_methods); return 1; } diff --git a/crypto/asn1/asn1.h b/crypto/asn1/asn1.h index 2e7e9b6810..86c5933e98 100644 --- a/crypto/asn1/asn1.h +++ b/crypto/asn1/asn1.h @@ -879,11 +879,13 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t); int ASN1_TIME_check(ASN1_TIME *t); ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); -int i2d_ASN1_SET(STACK *a, unsigned char **pp, - i2d_of_void *i2d, int ex_tag, int ex_class, int is_set); -STACK * d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, - d2i_of_void *d2i, void (*free_func)(void *), - int ex_tag, int ex_class); +int i2d_ASN1_SET(STACK_OF(BLOCK) *a, unsigned char **pp, + i2d_of_void *i2d, int ex_tag, int ex_class, + int is_set); +STACK_OF(BLOCK) *d2i_ASN1_SET(STACK_OF(BLOCK) **a, const unsigned char **pp, + long length, d2i_of_void *d2i, + void (*free_func)(BLOCK), int ex_tag, + int ex_class); #ifndef OPENSSL_NO_BIO int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); @@ -1035,9 +1037,9 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, unsigned char *data, int max_len); -STACK *ASN1_seq_unpack(const unsigned char *buf, int len, - d2i_of_void *d2i, void (*free_func)(void *)); -unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d, +STACK_OF(BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len, + d2i_of_void *d2i, void (*free_func)(BLOCK)); +unsigned char *ASN1_seq_pack(STACK_OF(BLOCK) *safes, i2d_of_void *i2d, unsigned char **buf, int *len ); void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i); void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); diff --git a/crypto/asn1/asn_pack.c b/crypto/asn1/asn_pack.c index e8b671b7b5..1e268dee46 100644 --- a/crypto/asn1/asn_pack.c +++ b/crypto/asn1/asn_pack.c @@ -66,10 +66,10 @@ /* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */ -STACK *ASN1_seq_unpack(const unsigned char *buf, int len, - d2i_of_void *d2i,void (*free_func)(void *)) +STACK_OF(BLOCK) *ASN1_seq_unpack(const unsigned char *buf, int len, + d2i_of_void *d2i, void (*free_func)(BLOCK)) { - STACK *sk; + STACK_OF(BLOCK) *sk; const unsigned char *pbuf; pbuf = buf; if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func, @@ -82,7 +82,7 @@ STACK *ASN1_seq_unpack(const unsigned char *buf, int len, * OPENSSL_malloc'ed buffer */ -unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d, +unsigned char *ASN1_seq_pack(STACK_OF(BLOCK) *safes, i2d_of_void *i2d, unsigned char **buf, int *len) { int safelen; diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c index f4831440fa..6f3ab00b36 100644 --- a/crypto/asn1/tasn_dec.c +++ b/crypto/asn1/tasn_dec.c @@ -668,11 +668,12 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, else { /* We've got a valid STACK: free up any items present */ - STACK *sktmp = (STACK *)*val; + STACK_OF(ASN1_VALUE) *sktmp + = (STACK_OF(ASN1_VALUE) *)*val; ASN1_VALUE *vtmp; - while(sk_num(sktmp) > 0) + while(sk_ASN1_VALUE_num(sktmp) > 0) { - vtmp = (ASN1_VALUE *)sk_pop(sktmp); + vtmp = sk_ASN1_VALUE_pop(sktmp); ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item)); } @@ -713,7 +714,8 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, goto err; } len -= p - q; - if (!sk_push((STACK *)*val, (char *)skfield)) + if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, + skfield)) { ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ERR_R_MALLOC_FAILURE); diff --git a/crypto/asn1/tasn_prn.c b/crypto/asn1/tasn_prn.c index d2830a5ead..361e93c59f 100644 --- a/crypto/asn1/tasn_prn.c +++ b/crypto/asn1/tasn_prn.c @@ -354,6 +354,8 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, { char *tname; ASN1_VALUE *skitem; + STACK_OF(ASN1_VALUE) *stack; + /* SET OF, SEQUENCE OF */ if (fname) { @@ -371,12 +373,13 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent, fname) <= 0) return 0; } - for(i = 0; i < sk_num((STACK *)*fld); i++) + stack = (STACK_OF(ASN1_VALUE) *)*fld; + for(i = 0; i < sk_ASN1_VALUE_num(stack); i++) { if ((i > 0) && (BIO_puts(out, "\n") <= 0)) return 0; - skitem = (ASN1_VALUE *)sk_value((STACK *)*fld, i); + skitem = sk_ASN1_VALUE_value(stack, i); if (!asn1_item_print_ctx(out, &skitem, indent + 2, ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx)) return 0; diff --git a/crypto/asn1/x_name.c b/crypto/asn1/x_name.c index 193f6d4403..3c9344c17f 100644 --- a/crypto/asn1/x_name.c +++ b/crypto/asn1/x_name.c @@ -63,6 +63,9 @@ #include <openssl/x509.h> #include "asn1_locl.h" +typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY; +DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY); + static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, @@ -76,7 +79,8 @@ static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it); static int x509_name_encode(X509_NAME *a); static int x509_name_canon(X509_NAME *a); static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in); -static int i2d_name_canon(STACK *intname, unsigned char **in); +static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname, + unsigned char **in); static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, @@ -165,27 +169,13 @@ static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) *pval = NULL; } -/* Used with sk_pop_free() to free up the internal representation. - * NB: we only free the STACK and not its contents because it is - * already present in the X509_NAME structure. - */ - -static void sk_internal_free(void *a) -{ - sk_free(a); -} - -static void canon_free(void *a) -{ - sk_X509_NAME_ENTRY_pop_free(a, X509_NAME_ENTRY_free); -} - static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx) { const unsigned char *p = *in, *q; - union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; + union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; + ASN1_VALUE *a; } intname = {NULL}; union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL}; int i, j, ret; STACK_OF(X509_NAME_ENTRY) *entries; @@ -206,8 +196,8 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, memcpy(nm.x->bytes->data, q, p - q); /* Convert internal representation to X509_NAME structure */ - for(i = 0; i < sk_num(intname.s); i++) { - entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname.s, i); + for(i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) { + entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i); for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { entry = sk_X509_NAME_ENTRY_value(entries, j); entry->set = i; @@ -216,7 +206,7 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, } sk_X509_NAME_ENTRY_free(entries); } - sk_free(intname.s); + sk_STACK_OF_X509_NAME_ENTRY_free(intname.s); ret = x509_name_canon(nm.x); if (!ret) goto err; @@ -249,22 +239,30 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT return ret; } +static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne) + { + sk_X509_NAME_ENTRY_free(ne); + } + static int x509_name_encode(X509_NAME *a) { - union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; + union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; + ASN1_VALUE *a; } intname = {NULL}; int len; unsigned char *p; STACK_OF(X509_NAME_ENTRY) *entries = NULL; X509_NAME_ENTRY *entry; int i, set = -1; - intname.s = sk_new_null(); + intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null(); if(!intname.s) goto memerr; for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { entry = sk_X509_NAME_ENTRY_value(a->entries, i); if(entry->set != set) { entries = sk_X509_NAME_ENTRY_new_null(); if(!entries) goto memerr; - if(!sk_push(intname.s, (char *)entries)) goto memerr; + if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s, + entries)) + goto memerr; set = entry->set; } if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; @@ -275,11 +273,13 @@ static int x509_name_encode(X509_NAME *a) p=(unsigned char *)a->bytes->data; ASN1_item_ex_i2d(&intname.a, &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); - sk_pop_free(intname.s, sk_internal_free); + sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, + local_sk_X509_NAME_ENTRY_free); a->modified = 0; return len; - memerr: - sk_pop_free(intname.s, sk_internal_free); +memerr: + sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, + local_sk_X509_NAME_ENTRY_free); ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); return -1; } @@ -311,10 +311,11 @@ static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, static int x509_name_canon(X509_NAME *a) { unsigned char *p; - STACK *intname = NULL; + STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL; STACK_OF(X509_NAME_ENTRY) *entries = NULL; X509_NAME_ENTRY *entry, *tmpentry = NULL; int i, set = -1, ret = 0; + if (a->canon_enc) { OPENSSL_free(a->canon_enc); @@ -326,7 +327,7 @@ static int x509_name_canon(X509_NAME *a) a->canon_enclen = 0; return 1; } - intname = sk_new_null(); + intname = sk_STACK_OF_X509_NAME_ENTRY_new_null(); if(!intname) goto err; for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) @@ -337,7 +338,7 @@ static int x509_name_canon(X509_NAME *a) entries = sk_X509_NAME_ENTRY_new_null(); if(!entries) goto err; - if(!sk_push(intname, (char *)entries)) + if(!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) goto err; set = entry->set; } @@ -370,7 +371,8 @@ static int x509_name_canon(X509_NAME *a) if (tmpentry) X509_NAME_ENTRY_free(tmpentry); if (intname) - sk_pop_free(intname, canon_free); + sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, + local_sk_X509_NAME_ENTRY_free); return ret; } @@ -467,14 +469,17 @@ static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) } -static int i2d_name_canon(STACK *intname, unsigned char **in) +static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, + unsigned char **in) { int i, len, ltmp; ASN1_VALUE *v; + STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname; + len = 0; - for (i = 0; i < sk_num(intname); i++) + for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) { - v = (ASN1_VALUE *)sk_value(intname, i); + v = sk_ASN1_VALUE_value(intname, i); ltmp = ASN1_item_ex_i2d(&v, in, ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1); if (ltmp < 0) |