diff options
Diffstat (limited to 'crypto/x509/x_name.c')
-rw-r--r-- | crypto/x509/x_name.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/crypto/x509/x_name.c b/crypto/x509/x_name.c index 53bbf722b6..8fd6566b01 100644 --- a/crypto/x509/x_name.c +++ b/crypto/x509/x_name.c @@ -28,7 +28,7 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx); -static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, +static int x509_name_ex_i2d(const ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it); static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it); @@ -36,10 +36,10 @@ 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, const ASN1_STRING *in); -static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) * intname, +static int i2d_name_canon(const STACK_OF(STACK_OF_X509_NAME_ENTRY) * intname, unsigned char **in); -static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, +static int x509_name_ex_print(BIO *out, const ASN1_VALUE **pval, int indent, const char *fname, const ASN1_PCTX *pctx); @@ -156,6 +156,7 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, int i, j, ret; STACK_OF(X509_NAME_ENTRY) *entries; X509_NAME_ENTRY *entry; + if (len > X509_NAME_MAX) len = X509_NAME_MAX; q = p; @@ -207,11 +208,12 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, return 0; } -static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, +static int x509_name_ex_i2d(const ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) { int ret; X509_NAME *a = (X509_NAME *)*val; + if (a->modified) { ret = x509_name_encode(a); if (ret < 0) @@ -232,7 +234,7 @@ static int x509_name_encode(X509_NAME *a) { union { STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; - ASN1_VALUE *a; + const ASN1_VALUE *a; } intname = { NULL }; @@ -241,6 +243,7 @@ static int x509_name_encode(X509_NAME *a) STACK_OF(X509_NAME_ENTRY) *entries = NULL; X509_NAME_ENTRY *entry; int i, set = -1; + intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null(); if (!intname.s) goto memerr; @@ -277,7 +280,7 @@ static int x509_name_encode(X509_NAME *a) return -1; } -static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, +static int x509_name_ex_print(BIO *out, const ASN1_VALUE **pval, int indent, const char *fname, const ASN1_PCTX *pctx) { @@ -460,11 +463,11 @@ static int asn1_string_canon(ASN1_STRING *out, const ASN1_STRING *in) } -static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) * _intname, +static int i2d_name_canon(const STACK_OF(STACK_OF_X509_NAME_ENTRY) * _intname, unsigned char **in) { int i, len, ltmp; - ASN1_VALUE *v; + const ASN1_VALUE *v; STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname; len = 0; @@ -479,14 +482,16 @@ static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) * _intname, return len; } -int X509_NAME_set(X509_NAME **xn, X509_NAME *name) +int X509_NAME_set(X509_NAME **xn, const X509_NAME *name) { + X509_NAME *name_copy; + if (*xn == name) return *xn != NULL; - if ((name = X509_NAME_dup(name)) == NULL) + if ((name_copy = X509_NAME_dup(name)) == NULL) return 0; X509_NAME_free(*xn); - *xn = name; + *xn = name_copy; return 1; } |