Respect ISO aliasing rules [from HEAD].

PR: 1296
This commit is contained in:
Andy Polyakov 2007-07-27 20:34:56 +00:00
parent 05ea800faf
commit 1040deb0c5

View file

@ -160,40 +160,40 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len
int tag, int aclass, char opt, ASN1_TLC *ctx) int tag, int aclass, char opt, ASN1_TLC *ctx)
{ {
const unsigned char *p = *in, *q; const unsigned char *p = *in, *q;
STACK *intname = NULL, **intname_pp = &intname; union { STACK *s; ASN1_VALUE *a; } intname = {NULL};
union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL};
int i, j, ret; int i, j, ret;
X509_NAME *nm = NULL, **nm_pp = &nm;
STACK_OF(X509_NAME_ENTRY) *entries; STACK_OF(X509_NAME_ENTRY) *entries;
X509_NAME_ENTRY *entry; X509_NAME_ENTRY *entry;
q = p; q = p;
/* Get internal representation of Name */ /* Get internal representation of Name */
ret = ASN1_item_ex_d2i((ASN1_VALUE **)intname_pp, ret = ASN1_item_ex_d2i(&intname.a,
&p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
tag, aclass, opt, ctx); tag, aclass, opt, ctx);
if(ret <= 0) return ret; if(ret <= 0) return ret;
if(*val) x509_name_ex_free(val, NULL); if(*val) x509_name_ex_free(val, NULL);
if(!x509_name_ex_new((ASN1_VALUE **)nm_pp, NULL)) goto err; if(!x509_name_ex_new(&nm.a, NULL)) goto err;
/* We've decoded it: now cache encoding */ /* We've decoded it: now cache encoding */
if(!BUF_MEM_grow(nm->bytes, p - q)) goto err; if(!BUF_MEM_grow(nm.x->bytes, p - q)) goto err;
memcpy(nm->bytes->data, q, p - q); memcpy(nm.x->bytes->data, q, p - q);
/* Convert internal representation to X509_NAME structure */ /* Convert internal representation to X509_NAME structure */
for(i = 0; i < sk_num(intname); i++) { for(i = 0; i < sk_num(intname.s); i++) {
entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname, i); entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname.s, i);
for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
entry = sk_X509_NAME_ENTRY_value(entries, j); entry = sk_X509_NAME_ENTRY_value(entries, j);
entry->set = i; entry->set = i;
if(!sk_X509_NAME_ENTRY_push(nm->entries, entry)) if(!sk_X509_NAME_ENTRY_push(nm.x->entries, entry))
goto err; goto err;
} }
sk_X509_NAME_ENTRY_free(entries); sk_X509_NAME_ENTRY_free(entries);
} }
sk_free(intname); sk_free(intname.s);
nm->modified = 0; nm.x->modified = 0;
*val = (ASN1_VALUE *)nm; *val = nm.a;
*in = p; *in = p;
return ret; return ret;
err: err:
@ -219,35 +219,35 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT
static int x509_name_encode(X509_NAME *a) static int x509_name_encode(X509_NAME *a)
{ {
STACK *intname = NULL, **intname_pp = &intname; union { STACK *s; ASN1_VALUE *a; } intname = {NULL};
int len; int len;
unsigned char *p; unsigned char *p;
STACK_OF(X509_NAME_ENTRY) *entries = NULL; STACK_OF(X509_NAME_ENTRY) *entries = NULL;
X509_NAME_ENTRY *entry; X509_NAME_ENTRY *entry;
int i, set = -1; int i, set = -1;
intname = sk_new_null(); intname.s = sk_new_null();
if(!intname) goto memerr; if(!intname.s) goto memerr;
for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
entry = sk_X509_NAME_ENTRY_value(a->entries, i); entry = sk_X509_NAME_ENTRY_value(a->entries, i);
if(entry->set != set) { if(entry->set != set) {
entries = sk_X509_NAME_ENTRY_new_null(); entries = sk_X509_NAME_ENTRY_new_null();
if(!entries) goto memerr; if(!entries) goto memerr;
if(!sk_push(intname, (char *)entries)) goto memerr; if(!sk_push(intname.s, (char *)entries)) goto memerr;
set = entry->set; set = entry->set;
} }
if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr;
} }
len = ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp, NULL, len = ASN1_item_ex_i2d(&intname.a, NULL,
ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
if (!BUF_MEM_grow(a->bytes,len)) goto memerr; if (!BUF_MEM_grow(a->bytes,len)) goto memerr;
p=(unsigned char *)a->bytes->data; p=(unsigned char *)a->bytes->data;
ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp, ASN1_item_ex_i2d(&intname.a,
&p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
sk_pop_free(intname, sk_internal_free); sk_pop_free(intname.s, sk_internal_free);
a->modified = 0; a->modified = 0;
return len; return len;
memerr: memerr:
sk_pop_free(intname, sk_internal_free); sk_pop_free(intname.s, sk_internal_free);
ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE);
return -1; return -1;
} }