Use sk_*_new_null() instead of sk_*_new(NULL), since that takes care
[openssl.git] / crypto / x509v3 / v3_crld.c
index ece494489f28f7dc2a2bca2ae28b654b8898fb7a..67feea40171fbe1e3fd1537d86e0dabab74c7983 100644 (file)
 #include <openssl/asn1_mac.h>
 #include <openssl/x509v3.h>
 
-static STACK *i2v_crld(X509V3_EXT_METHOD *method, STACK_OF(DIST_POINT) *crld,
-                                                        STACK *extlist);
+static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
+               STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist);
 static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
-                                                X509V3_CTX *ctx, STACK *nval);
+                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
 
 X509V3_EXT_METHOD v3_crld = {
 NID_crl_distribution_points, X509V3_EXT_MULTILINE,
 (X509V3_EXT_NEW)CRL_DIST_POINTS_new,
-CRL_DIST_POINTS_free,
+(X509V3_EXT_FREE)CRL_DIST_POINTS_free,
 (X509V3_EXT_D2I)d2i_CRL_DIST_POINTS,
-i2d_CRL_DIST_POINTS,
+(X509V3_EXT_I2D)i2d_CRL_DIST_POINTS,
 NULL, NULL,
 (X509V3_EXT_I2V)i2v_crld,
 (X509V3_EXT_V2I)v2i_crld,
 NULL, NULL, NULL
 };
 
-static STACK *i2v_crld(X509V3_EXT_METHOD *method, STACK_OF(DIST_POINT) *crld,
-                                                                STACK *exts)
+static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
+                       STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
 {
        DIST_POINT *point;
        int i;
        for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
                point = sk_DIST_POINT_value(crld, i);
-               if(point->distpoint->fullname) {
+               if(point->distpoint && point->distpoint->fullname) {
                        exts = i2v_GENERAL_NAMES(NULL,
                                         point->distpoint->fullname, exts);
                }
@@ -95,24 +95,24 @@ static STACK *i2v_crld(X509V3_EXT_METHOD *method, STACK_OF(DIST_POINT) *crld,
                        X509V3_add_value("reasons","<UNSUPPORTED>", &exts);
                if(point->CRLissuer)
                        X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts);
-               if(point->distpoint->relativename)
+               if(point->distpoint && point->distpoint->relativename)
                        X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
        }
        return exts;
 }
 
 static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
-                                                X509V3_CTX *ctx, STACK *nval)
+                               X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
 {
        STACK_OF(DIST_POINT) *crld = NULL;
        STACK_OF(GENERAL_NAME) *gens = NULL;
        GENERAL_NAME *gen = NULL;
        CONF_VALUE *cnf;
        int i;
-       if(!(crld = sk_DIST_POINT_new(NULL))) goto merr;
-       for(i = 0; i < sk_num(nval); i++) {
+       if(!(crld = sk_DIST_POINT_new_null())) goto merr;
+       for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
                DIST_POINT *point;
-               cnf = (CONF_VALUE *)sk_value(nval, i);
+               cnf = sk_CONF_VALUE_value(nval, i);
                if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err; 
                if(!(gens = GENERAL_NAMES_new())) goto merr;
                if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
@@ -211,20 +211,20 @@ void DIST_POINT_free(DIST_POINT *a)
 {
        if (a == NULL) return;
        DIST_POINT_NAME_free(a->distpoint);
-       ASN1_BIT_STRING_free(a->reasons);
+       M_ASN1_BIT_STRING_free(a->reasons);
        sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free);
-       Free ((char *)a);
+       OPENSSL_free (a);
 }
 
 int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
 {
-       int v = 0;
        M_ASN1_I2D_vars(a);
 
        if(a->fullname) {
                M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES);
        } else {
-               M_ASN1_I2D_len_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
+               M_ASN1_I2D_len_IMP_SET_opt_type(X509_NAME_ENTRY,
+                               a->relativename, i2d_X509_NAME_ENTRY, 1);
        }
 
        /* Don't want a SEQUENCE so... */
@@ -234,7 +234,8 @@ int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
        if(a->fullname) {
                M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0);
        } else {
-               M_ASN1_I2D_put_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
+               M_ASN1_I2D_put_IMP_SET_opt_type(X509_NAME_ENTRY,
+                               a->relativename, i2d_X509_NAME_ENTRY, 1);
        }
        M_ASN1_I2D_finish();
 }
@@ -253,9 +254,9 @@ DIST_POINT_NAME *DIST_POINT_NAME_new(void)
 void DIST_POINT_NAME_free(DIST_POINT_NAME *a)
 {
        if (a == NULL) return;
-       X509_NAME_free(a->relativename);
+       sk_X509_NAME_ENTRY_pop_free(a->relativename, X509_NAME_ENTRY_free);
        sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free);
-       Free ((char *)a);
+       OPENSSL_free (a);
 }
 
 DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
@@ -273,7 +274,8 @@ DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
                M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES,
                                                        V_ASN1_SEQUENCE);
        } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) {
-               M_ASN1_D2I_get_EXP_opt (ret->relativename, d2i_X509_NAME, 1);
+               M_ASN1_D2I_get_IMP_set_opt_type (X509_NAME_ENTRY,
+                       ret->relativename, d2i_X509_NAME_ENTRY, X509_NAME_ENTRY_free, 1);
        } else {
                c.error = ASN1_R_BAD_TAG;
                goto err;