summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509/x509_att.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/x509/x509_att.c')
-rw-r--r--src/lib/libcrypto/x509/x509_att.c45
1 files changed, 9 insertions, 36 deletions
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
index 511b49d589..0bae3d32a1 100644
--- a/src/lib/libcrypto/x509/x509_att.c
+++ b/src/lib/libcrypto/x509/x509_att.c
@@ -67,7 +67,8 @@
67 67
68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x) 68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x)
69{ 69{
70 return sk_X509_ATTRIBUTE_num(x); 70 if (!x) return 0;
71 return(sk_X509_ATTRIBUTE_num(x));
71} 72}
72 73
73int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, 74int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
@@ -124,13 +125,7 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
124 X509_ATTRIBUTE *new_attr=NULL; 125 X509_ATTRIBUTE *new_attr=NULL;
125 STACK_OF(X509_ATTRIBUTE) *sk=NULL; 126 STACK_OF(X509_ATTRIBUTE) *sk=NULL;
126 127
127 if (x == NULL) 128 if ((x != NULL) && (*x == NULL))
128 {
129 X509err(X509_F_X509AT_ADD1_ATTR, ERR_R_PASSED_NULL_PARAMETER);
130 goto err2;
131 }
132
133 if (*x == NULL)
134 { 129 {
135 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL) 130 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL)
136 goto err; 131 goto err;
@@ -142,11 +137,11 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
142 goto err2; 137 goto err2;
143 if (!sk_X509_ATTRIBUTE_push(sk,new_attr)) 138 if (!sk_X509_ATTRIBUTE_push(sk,new_attr))
144 goto err; 139 goto err;
145 if (*x == NULL) 140 if ((x != NULL) && (*x == NULL))
146 *x=sk; 141 *x=sk;
147 return(sk); 142 return(sk);
148err: 143err:
149 X509err(X509_F_X509AT_ADD1_ATTR,ERR_R_MALLOC_FAILURE); 144 X509err(X509_F_X509_ADD_ATTR,ERR_R_MALLOC_FAILURE);
150err2: 145err2:
151 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr); 146 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr);
152 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk); 147 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk);
@@ -192,22 +187,6 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
192 return ret; 187 return ret;
193} 188}
194 189
195void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x,
196 ASN1_OBJECT *obj, int lastpos, int type)
197{
198 int i;
199 X509_ATTRIBUTE *at;
200 i = X509at_get_attr_by_OBJ(x, obj, lastpos);
201 if (i == -1)
202 return NULL;
203 if ((lastpos <= -2) && (X509at_get_attr_by_OBJ(x, obj, i) != -1))
204 return NULL;
205 at = X509at_get_attr(x, i);
206 if (lastpos <= -3 && (X509_ATTRIBUTE_count(at) != 1))
207 return NULL;
208 return X509_ATTRIBUTE_get0_data(at, 0, type, NULL);
209}
210
211X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, 190X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
212 int atrtype, const void *data, int len) 191 int atrtype, const void *data, int len)
213{ 192{
@@ -285,8 +264,8 @@ int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj)
285int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len) 264int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len)
286{ 265{
287 ASN1_TYPE *ttmp; 266 ASN1_TYPE *ttmp;
288 ASN1_STRING *stmp = NULL; 267 ASN1_STRING *stmp;
289 int atype = 0; 268 int atype;
290 if (!attr) return 0; 269 if (!attr) return 0;
291 if(attrtype & MBSTRING_FLAG) { 270 if(attrtype & MBSTRING_FLAG) {
292 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype, 271 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
@@ -296,22 +275,16 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *dat
296 return 0; 275 return 0;
297 } 276 }
298 atype = stmp->type; 277 atype = stmp->type;
299 } else if (len != -1){ 278 } else {
300 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err; 279 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
301 if(!ASN1_STRING_set(stmp, data, len)) goto err; 280 if(!ASN1_STRING_set(stmp, data, len)) goto err;
302 atype = attrtype; 281 atype = attrtype;
303 } 282 }
304 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err; 283 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
305 if(!(ttmp = ASN1_TYPE_new())) goto err; 284 if(!(ttmp = ASN1_TYPE_new())) goto err;
306 if (len == -1)
307 {
308 if (!ASN1_TYPE_set1(ttmp, attrtype, data))
309 goto err;
310 }
311 else
312 ASN1_TYPE_set(ttmp, atype, stmp);
313 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err; 285 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
314 attr->single = 0; 286 attr->single = 0;
287 ASN1_TYPE_set(ttmp, atype, stmp);
315 return 1; 288 return 1;
316 err: 289 err:
317 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE); 290 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);