diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/x_name.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/x_name.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c index 31f3377b64..04380abc3f 100644 --- a/src/lib/libcrypto/asn1/x_name.c +++ b/src/lib/libcrypto/asn1/x_name.c | |||
| @@ -61,7 +61,7 @@ | |||
| 61 | #include <openssl/asn1t.h> | 61 | #include <openssl/asn1t.h> |
| 62 | #include <openssl/x509.h> | 62 | #include <openssl/x509.h> |
| 63 | 63 | ||
| 64 | static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it, | 64 | static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, |
| 65 | int tag, int aclass, char opt, ASN1_TLC *ctx); | 65 | int tag, int aclass, char opt, ASN1_TLC *ctx); |
| 66 | 66 | ||
| 67 | static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | 67 | static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); |
| @@ -123,7 +123,7 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) | |||
| 123 | return 1; | 123 | return 1; |
| 124 | 124 | ||
| 125 | memerr: | 125 | memerr: |
| 126 | ASN1err(ASN1_F_X509_NAME_NEW, ERR_R_MALLOC_FAILURE); | 126 | ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); |
| 127 | if (ret) | 127 | if (ret) |
| 128 | { | 128 | { |
| 129 | if (ret->entries) | 129 | if (ret->entries) |
| @@ -156,48 +156,48 @@ static void sk_internal_free(void *a) | |||
| 156 | sk_free(a); | 156 | sk_free(a); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it, | 159 | static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, |
| 160 | int tag, int aclass, char opt, ASN1_TLC *ctx) | 160 | int tag, int aclass, char opt, ASN1_TLC *ctx) |
| 161 | { | 161 | { |
| 162 | unsigned char *p = *in, *q; | 162 | const unsigned char *p = *in, *q; |
| 163 | STACK *intname = NULL, **intname_pp = &intname; | 163 | union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; |
| 164 | union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL}; | ||
| 164 | int i, j, ret; | 165 | int i, j, ret; |
| 165 | X509_NAME *nm = NULL, **nm_pp = &nm; | ||
| 166 | STACK_OF(X509_NAME_ENTRY) *entries; | 166 | STACK_OF(X509_NAME_ENTRY) *entries; |
| 167 | X509_NAME_ENTRY *entry; | 167 | X509_NAME_ENTRY *entry; |
| 168 | q = p; | 168 | q = p; |
| 169 | 169 | ||
| 170 | /* Get internal representation of Name */ | 170 | /* Get internal representation of Name */ |
| 171 | ret = ASN1_item_ex_d2i((ASN1_VALUE **)intname_pp, | 171 | ret = ASN1_item_ex_d2i(&intname.a, |
| 172 | &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), | 172 | &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), |
| 173 | tag, aclass, opt, ctx); | 173 | tag, aclass, opt, ctx); |
| 174 | 174 | ||
| 175 | if(ret <= 0) return ret; | 175 | if(ret <= 0) return ret; |
| 176 | 176 | ||
| 177 | if(*val) x509_name_ex_free(val, NULL); | 177 | if(*val) x509_name_ex_free(val, NULL); |
| 178 | if(!x509_name_ex_new((ASN1_VALUE **)nm_pp, NULL)) goto err; | 178 | if(!x509_name_ex_new(&nm.a, NULL)) goto err; |
| 179 | /* We've decoded it: now cache encoding */ | 179 | /* We've decoded it: now cache encoding */ |
| 180 | if(!BUF_MEM_grow(nm->bytes, p - q)) goto err; | 180 | if(!BUF_MEM_grow(nm.x->bytes, p - q)) goto err; |
| 181 | memcpy(nm->bytes->data, q, p - q); | 181 | memcpy(nm.x->bytes->data, q, p - q); |
| 182 | 182 | ||
| 183 | /* Convert internal representation to X509_NAME structure */ | 183 | /* Convert internal representation to X509_NAME structure */ |
| 184 | for(i = 0; i < sk_num(intname); i++) { | 184 | for(i = 0; i < sk_num(intname.s); i++) { |
| 185 | entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname, i); | 185 | entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname.s, i); |
| 186 | for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { | 186 | for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { |
| 187 | entry = sk_X509_NAME_ENTRY_value(entries, j); | 187 | entry = sk_X509_NAME_ENTRY_value(entries, j); |
| 188 | entry->set = i; | 188 | entry->set = i; |
| 189 | if(!sk_X509_NAME_ENTRY_push(nm->entries, entry)) | 189 | if(!sk_X509_NAME_ENTRY_push(nm.x->entries, entry)) |
| 190 | goto err; | 190 | goto err; |
| 191 | } | 191 | } |
| 192 | sk_X509_NAME_ENTRY_free(entries); | 192 | sk_X509_NAME_ENTRY_free(entries); |
| 193 | } | 193 | } |
| 194 | sk_free(intname); | 194 | sk_free(intname.s); |
| 195 | nm->modified = 0; | 195 | nm.x->modified = 0; |
| 196 | *val = (ASN1_VALUE *)nm; | 196 | *val = nm.a; |
| 197 | *in = p; | 197 | *in = p; |
| 198 | return ret; | 198 | return ret; |
| 199 | err: | 199 | err: |
| 200 | ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_NESTED_ASN1_ERROR); | 200 | ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR); |
| 201 | return 0; | 201 | return 0; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| @@ -219,36 +219,36 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT | |||
| 219 | 219 | ||
| 220 | static int x509_name_encode(X509_NAME *a) | 220 | static int x509_name_encode(X509_NAME *a) |
| 221 | { | 221 | { |
| 222 | STACK *intname = NULL, **intname_pp = &intname; | 222 | union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; |
| 223 | int len; | 223 | int len; |
| 224 | unsigned char *p; | 224 | unsigned char *p; |
| 225 | STACK_OF(X509_NAME_ENTRY) *entries = NULL; | 225 | STACK_OF(X509_NAME_ENTRY) *entries = NULL; |
| 226 | X509_NAME_ENTRY *entry; | 226 | X509_NAME_ENTRY *entry; |
| 227 | int i, set = -1; | 227 | int i, set = -1; |
| 228 | intname = sk_new_null(); | 228 | intname.s = sk_new_null(); |
| 229 | if(!intname) goto memerr; | 229 | if(!intname.s) goto memerr; |
| 230 | for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { | 230 | for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { |
| 231 | entry = sk_X509_NAME_ENTRY_value(a->entries, i); | 231 | entry = sk_X509_NAME_ENTRY_value(a->entries, i); |
| 232 | if(entry->set != set) { | 232 | if(entry->set != set) { |
| 233 | entries = sk_X509_NAME_ENTRY_new_null(); | 233 | entries = sk_X509_NAME_ENTRY_new_null(); |
| 234 | if(!entries) goto memerr; | 234 | if(!entries) goto memerr; |
| 235 | if(!sk_push(intname, (char *)entries)) goto memerr; | 235 | if(!sk_push(intname.s, (char *)entries)) goto memerr; |
| 236 | set = entry->set; | 236 | set = entry->set; |
| 237 | } | 237 | } |
| 238 | if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; | 238 | if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; |
| 239 | } | 239 | } |
| 240 | len = ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp, NULL, | 240 | len = ASN1_item_ex_i2d(&intname.a, NULL, |
| 241 | ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); | 241 | ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); |
| 242 | if (!BUF_MEM_grow(a->bytes,len)) goto memerr; | 242 | if (!BUF_MEM_grow(a->bytes,len)) goto memerr; |
| 243 | p=(unsigned char *)a->bytes->data; | 243 | p=(unsigned char *)a->bytes->data; |
| 244 | ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp, | 244 | ASN1_item_ex_i2d(&intname.a, |
| 245 | &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); | 245 | &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); |
| 246 | sk_pop_free(intname, sk_internal_free); | 246 | sk_pop_free(intname.s, sk_internal_free); |
| 247 | a->modified = 0; | 247 | a->modified = 0; |
| 248 | return len; | 248 | return len; |
| 249 | memerr: | 249 | memerr: |
| 250 | sk_pop_free(intname, sk_internal_free); | 250 | sk_pop_free(intname.s, sk_internal_free); |
| 251 | ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_MALLOC_FAILURE); | 251 | ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); |
| 252 | return -1; | 252 | return -1; |
| 253 | } | 253 | } |
| 254 | 254 | ||
