OpenCoverage

x_name.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509/x_name.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stdio.h>-
11#include "internal/ctype.h"-
12#include "internal/cryptlib.h"-
13#include <openssl/asn1t.h>-
14#include <openssl/x509.h>-
15#include "internal/x509_int.h"-
16#include "internal/asn1_int.h"-
17#include "x509_lcl.h"-
18-
19/*-
20 * Maximum length of X509_NAME: much larger than anything we should-
21 * ever see in practice.-
22 */-
23-
24#define X509_NAME_MAX (1024 * 1024)-
25-
26static int x509_name_ex_d2i(ASN1_VALUE **val,-
27 const unsigned char **in, long len,-
28 const ASN1_ITEM *it,-
29 int tag, int aclass, char opt, ASN1_TLC *ctx);-
30-
31static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out,-
32 const ASN1_ITEM *it, int tag, int aclass);-
33static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it);-
34static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it);-
35-
36static int x509_name_encode(X509_NAME *a);-
37static int x509_name_canon(X509_NAME *a);-
38static int asn1_string_canon(ASN1_STRING *out, const ASN1_STRING *in);-
39static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) * intname,-
40 unsigned char **in);-
41-
42static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,-
43 int indent,-
44 const char *fname, const ASN1_PCTX *pctx);-
45-
46ASN1_SEQUENCE(X509_NAME_ENTRY) = {-
47 ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT),-
48 ASN1_SIMPLE(X509_NAME_ENTRY, value, ASN1_PRINTABLE)-
49} ASN1_SEQUENCE_END(X509_NAME_ENTRY)-
50-
51IMPLEMENT_ASN1_FUNCTIONS(X509_NAME_ENTRY)
executed 272317 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
never executed: return (X509_NAME_ENTRY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(X509_NAME_ENTRY_it)));
never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(X509_NAME_ENTRY_it)));
executed 120966 times by 1 test: return (X509_NAME_ENTRY *)ASN1_item_new((&(X509_NAME_ENTRY_it)));
Executed by:
  • libcrypto.so.1.1
0-272317
52IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY)
executed 19686 times by 1 test: return ASN1_item_dup((&(X509_NAME_ENTRY_it)), x);
Executed by:
  • libcrypto.so.1.1
19686
53-
54/*-
55 * For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY } so-
56 * declare two template wrappers for this-
57 */-
58-
59ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) =-
60 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY)-
61static_ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES)-
62-
63ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) =-
64 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES)-
65static_ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL)-
66-
67/*-
68 * Normally that's where it would end: we'd have two nested STACK structures-
69 * representing the ASN1. Unfortunately X509_NAME uses a completely different-
70 * form and caches encodings so we have to process the internal form and-
71 * convert to the external form.-
72 */-
73-
74static const ASN1_EXTERN_FUNCS x509_name_ff = {-
75 NULL,-
76 x509_name_ex_new,-
77 x509_name_ex_free,-
78 0, /* Default clear behaviour is OK */-
79 x509_name_ex_d2i,-
80 x509_name_ex_i2d,-
81 x509_name_ex_print-
82};-
83-
84IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff)-
85-
86IMPLEMENT_ASN1_FUNCTIONS(X509_NAME)
executed 25089 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
executed 50 times by 1 test: return (X509_NAME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(X509_NAME_it)));
Executed by:
  • libcrypto.so.1.1
executed 5217 times by 1 test: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(X509_NAME_it)));
Executed by:
  • libcrypto.so.1.1
executed 412 times by 1 test: return (X509_NAME *)ASN1_item_new((&(X509_NAME_it)));
Executed by:
  • libcrypto.so.1.1
50-25089
87-
88IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)
executed 7141 times by 1 test: return ASN1_item_dup((&(X509_NAME_it)), x);
Executed by:
  • libcrypto.so.1.1
7141
89-
90static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)-
91{-
92 X509_NAME *ret = OPENSSL_zalloc(sizeof(*ret));-
93-
94 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 274790 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-274790
95 goto memerr;
never executed: goto memerr;
0
96 if ((ret->entries = sk_X509_NAME_ENTRY_new_null()) == NULL)
(ret->entries ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 274790 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-274790
97 goto memerr;
never executed: goto memerr;
0
98 if ((ret->bytes = BUF_MEM_new()) == NULL)
(ret->bytes = ...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 274790 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-274790
99 goto memerr;
never executed: goto memerr;
0
100 ret->modified = 1;-
101 *val = (ASN1_VALUE *)ret;-
102 return 1;
executed 274790 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
274790
103-
104 memerr:-
105 ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE);-
106 if (ret) {
retDescription
TRUEnever evaluated
FALSEnever evaluated
0
107 sk_X509_NAME_ENTRY_free(ret->entries);-
108 OPENSSL_free(ret);-
109 }
never executed: end of block
0
110 return 0;
never executed: return 0;
0
111}-
112-
113static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)-
114{-
115 X509_NAME *a;-
116-
117 if (!pval || !*pval)
!pvalDescription
TRUEnever evaluated
FALSEevaluated 274790 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!*pvalDescription
TRUEnever evaluated
FALSEevaluated 274790 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-274790
118 return;
never executed: return;
0
119 a = (X509_NAME *)*pval;-
120-
121 BUF_MEM_free(a->bytes);-
122 sk_X509_NAME_ENTRY_pop_free(a->entries, X509_NAME_ENTRY_free);-
123 OPENSSL_free(a->canon_enc);-
124 OPENSSL_free(a);-
125 *pval = NULL;-
126}
executed 274790 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
274790
127-
128static void local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne)-
129{-
130 sk_X509_NAME_ENTRY_free(ne);-
131}
executed 97560 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
97560
132-
133static void local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne)-
134{-
135 sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free);-
136}
executed 99013 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
99013
137-
138static int x509_name_ex_d2i(ASN1_VALUE **val,-
139 const unsigned char **in, long len,-
140 const ASN1_ITEM *it, int tag, int aclass,-
141 char opt, ASN1_TLC *ctx)-
142{-
143 const unsigned char *p = *in, *q;-
144 union {-
145 STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;-
146 ASN1_VALUE *a;-
147 } intname = {-
148 NULL-
149 };-
150 union {-
151 X509_NAME *x;-
152 ASN1_VALUE *a;-
153 } nm = {-
154 NULL-
155 };-
156 int i, j, ret;-
157 STACK_OF(X509_NAME_ENTRY) *entries;-
158 X509_NAME_ENTRY *entry;-
159 if (len > X509_NAME_MAX)
len > (1024 * 1024)Description
TRUEnever evaluated
FALSEevaluated 138785 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-138785
160 len = X509_NAME_MAX;
never executed: len = (1024 * 1024);
0
161 q = p;-
162-
163 /* Get internal representation of Name */-
164 ret = ASN1_item_ex_d2i(&intname.a,-
165 &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL),-
166 tag, aclass, opt, ctx);-
167-
168 if (ret <= 0)
ret <= 0Description
TRUEevaluated 15104 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 123681 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
15104-123681
169 return ret;
executed 15104 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
15104
170-
171 if (*val)
*valDescription
TRUEevaluated 112126 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11555 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
11555-112126
172 x509_name_ex_free(val, NULL);
executed 112126 times by 1 test: x509_name_ex_free(val, ((void *)0) );
Executed by:
  • libcrypto.so.1.1
112126
173 if (!x509_name_ex_new(&nm.a, NULL))
!x509_name_ex_... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 123681 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-123681
174 goto err;
never executed: goto err;
0
175 /* We've decoded it: now cache encoding */-
176 if (!BUF_MEM_grow(nm.x->bytes, p - q))
!BUF_MEM_grow(...>bytes, p - q)Description
TRUEnever evaluated
FALSEevaluated 123681 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-123681
177 goto err;
never executed: goto err;
0
178 memcpy(nm.x->bytes->data, q, p - q);-
179-
180 /* Convert internal representation to X509_NAME structure */-
181 for (i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) {
i < sk_STACK_O...num(intname.s)Description
TRUEevaluated 79944 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 123681 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
79944-123681
182 entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i);-
183 for (j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
j < sk_X509_NA...Y_num(entries)Description
TRUEevaluated 95547 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 79944 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
79944-95547
184 entry = sk_X509_NAME_ENTRY_value(entries, j);-
185 entry->set = i;-
186 if (!sk_X509_NAME_ENTRY_push(nm.x->entries, entry))
!sk_X509_NAME_...ntries, entry)Description
TRUEnever evaluated
FALSEevaluated 95547 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-95547
187 goto err;
never executed: goto err;
0
188 sk_X509_NAME_ENTRY_set(entries, j, NULL);-
189 }
executed 95547 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
95547
190 }
executed 79944 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
79944
191 ret = x509_name_canon(nm.x);-
192 if (!ret)
!retDescription
TRUEevaluated 1163 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 122518 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1163-122518
193 goto err;
executed 1163 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
1163
194 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,-
195 local_sk_X509_NAME_ENTRY_free);-
196 nm.x->modified = 0;-
197 *val = nm.a;-
198 *in = p;-
199 return ret;
executed 122518 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
122518
200-
201 err:-
202 if (nm.x != NULL)
nm.x != ((void *)0)Description
TRUEevaluated 1163 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1163
203 X509_NAME_free(nm.x);
executed 1163 times by 1 test: X509_NAME_free(nm.x);
Executed by:
  • libcrypto.so.1.1
1163
204 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,-
205 local_sk_X509_NAME_ENTRY_pop_free);-
206 ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR);-
207 return 0;
executed 1163 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
1163
208}-
209-
210static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out,-
211 const ASN1_ITEM *it, int tag, int aclass)-
212{-
213 int ret;-
214 X509_NAME *a = (X509_NAME *)*val;-
215 if (a->modified) {
a->modifiedDescription
TRUEevaluated 4549 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27804 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4549-27804
216 ret = x509_name_encode(a);-
217 if (ret < 0)
ret < 0Description
TRUEnever evaluated
FALSEevaluated 4549 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4549
218 return ret;
never executed: return ret;
0
219 ret = x509_name_canon(a);-
220 if (ret < 0)
ret < 0Description
TRUEnever evaluated
FALSEevaluated 4549 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4549
221 return ret;
never executed: return ret;
0
222 }
executed 4549 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4549
223 ret = a->bytes->length;-
224 if (out != NULL) {
out != ((void *)0)Description
TRUEevaluated 9110 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 23243 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9110-23243
225 memcpy(*out, a->bytes->data, ret);-
226 *out += ret;-
227 }
executed 9110 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9110
228 return ret;
executed 32353 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
32353
229}-
230-
231static int x509_name_encode(X509_NAME *a)-
232{-
233 union {-
234 STACK_OF(STACK_OF_X509_NAME_ENTRY) *s;-
235 ASN1_VALUE *a;-
236 } intname = {-
237 NULL-
238 };-
239 int len;-
240 unsigned char *p;-
241 STACK_OF(X509_NAME_ENTRY) *entries = NULL;-
242 X509_NAME_ENTRY *entry;-
243 int i, set = -1;-
244 intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null();-
245 if (!intname.s)
!intname.sDescription
TRUEnever evaluated
FALSEevaluated 4549 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4549
246 goto memerr;
never executed: goto memerr;
0
247 for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
i < sk_X509_NA...um(a->entries)Description
TRUEevaluated 25517 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4549 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4549-25517
248 entry = sk_X509_NAME_ENTRY_value(a->entries, i);-
249 if (entry->set != set) {
entry->set != setDescription
TRUEevaluated 22300 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3217 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3217-22300
250 entries = sk_X509_NAME_ENTRY_new_null();-
251 if (!entries)
!entriesDescription
TRUEnever evaluated
FALSEevaluated 22300 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-22300
252 goto memerr;
never executed: goto memerr;
0
253 if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s, entries)) {
!sk_STACK_OF_X...me.s, entries)Description
TRUEnever evaluated
FALSEevaluated 22300 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-22300
254 sk_X509_NAME_ENTRY_free(entries);-
255 goto memerr;
never executed: goto memerr;
0
256 }-
257 set = entry->set;-
258 }
executed 22300 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
22300
259 if (!sk_X509_NAME_ENTRY_push(entries, entry))
!sk_X509_NAME_...ntries, entry)Description
TRUEnever evaluated
FALSEevaluated 25517 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-25517
260 goto memerr;
never executed: goto memerr;
0
261 }
executed 25517 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
25517
262 len = ASN1_item_ex_i2d(&intname.a, NULL,-
263 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);-
264 if (!BUF_MEM_grow(a->bytes, len))
!BUF_MEM_grow(a->bytes, len)Description
TRUEnever evaluated
FALSEevaluated 4549 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4549
265 goto memerr;
never executed: goto memerr;
0
266 p = (unsigned char *)a->bytes->data;-
267 ASN1_item_ex_i2d(&intname.a,-
268 &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);-
269 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,-
270 local_sk_X509_NAME_ENTRY_free);-
271 a->modified = 0;-
272 return len;
executed 4549 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
4549
273 memerr:-
274 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s,-
275 local_sk_X509_NAME_ENTRY_free);-
276 ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE);-
277 return -1;
never executed: return -1;
0
278}-
279-
280static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval,-
281 int indent,-
282 const char *fname, const ASN1_PCTX *pctx)-
283{-
284 if (X509_NAME_print_ex(out, (const X509_NAME *)*pval,
X509_NAME_prin...nm_flags) <= 0Description
TRUEnever evaluated
FALSEevaluated 1163 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1163
285 indent, pctx->nm_flags) <= 0)
X509_NAME_prin...nm_flags) <= 0Description
TRUEnever evaluated
FALSEevaluated 1163 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1163
286 return 0;
never executed: return 0;
0
287 return 2;
executed 1163 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
1163
288}-
289-
290/*-
291 * This function generates the canonical encoding of the Name structure. In-
292 * it all strings are converted to UTF8, leading, trailing and multiple-
293 * spaces collapsed, converted to lower case and the leading SEQUENCE header-
294 * removed. In future we could also normalize the UTF8 too. By doing this-
295 * comparison of Name structures can be rapidly performed by just using-
296 * memcmp() of the canonical encoding. By omitting the leading SEQUENCE name-
297 * constraints of type dirName can also be checked with a simple memcmp().-
298 */-
299-
300static int x509_name_canon(X509_NAME *a)-
301{-
302 unsigned char *p;-
303 STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname;-
304 STACK_OF(X509_NAME_ENTRY) *entries = NULL;-
305 X509_NAME_ENTRY *entry, *tmpentry = NULL;-
306 int i, set = -1, ret = 0, len;-
307-
308 OPENSSL_free(a->canon_enc);-
309 a->canon_enc = NULL;-
310 /* Special case: empty X509_NAME => null encoding */-
311 if (sk_X509_NAME_ENTRY_num(a->entries) == 0) {
sk_X509_NAME_E...>entries) == 0Description
TRUEevaluated 87456 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 40774 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
40774-87456
312 a->canon_enclen = 0;-
313 return 1;
executed 87456 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
87456
314 }-
315 intname = sk_STACK_OF_X509_NAME_ENTRY_new_null();-
316 if (intname == NULL) {
intname == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 40774 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-40774
317 X509err(X509_F_X509_NAME_CANON, ERR_R_MALLOC_FAILURE);-
318 goto err;
never executed: goto err;
0
319 }-
320 for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
i < sk_X509_NA...um(a->entries)Description
TRUEevaluated 120201 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 36118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
36118-120201
321 entry = sk_X509_NAME_ENTRY_value(a->entries, i);-
322 if (entry->set != set) {
entry->set != setDescription
TRUEevaluated 94329 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 25872 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
25872-94329
323 entries = sk_X509_NAME_ENTRY_new_null();-
324 if (entries == NULL)
entries == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 94329 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-94329
325 goto err;
never executed: goto err;
0
326 if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) {
!sk_STACK_OF_X...name, entries)Description
TRUEnever evaluated
FALSEevaluated 94329 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-94329
327 sk_X509_NAME_ENTRY_free(entries);-
328 X509err(X509_F_X509_NAME_CANON, ERR_R_MALLOC_FAILURE);-
329 goto err;
never executed: goto err;
0
330 }-
331 set = entry->set;-
332 }
executed 94329 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
94329
333 tmpentry = X509_NAME_ENTRY_new();-
334 if (tmpentry == NULL) {
tmpentry == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 120201 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-120201
335 X509err(X509_F_X509_NAME_CANON, ERR_R_MALLOC_FAILURE);-
336 goto err;
never executed: goto err;
0
337 }-
338 tmpentry->object = OBJ_dup(entry->object);-
339 if (tmpentry->object == NULL) {
tmpentry->obje...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 120201 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-120201
340 X509err(X509_F_X509_NAME_CANON, ERR_R_MALLOC_FAILURE);-
341 goto err;
never executed: goto err;
0
342 }-
343 if (!asn1_string_canon(tmpentry->value, entry->value))
!asn1_string_c... entry->value)Description
TRUEevaluated 4656 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 115545 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4656-115545
344 goto err;
executed 4656 times by 1 test: goto err;
Executed by:
  • libcrypto.so.1.1
4656
345 if (!sk_X509_NAME_ENTRY_push(entries, tmpentry)) {
!sk_X509_NAME_...ies, tmpentry)Description
TRUEnever evaluated
FALSEevaluated 115545 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-115545
346 X509err(X509_F_X509_NAME_CANON, ERR_R_MALLOC_FAILURE);-
347 goto err;
never executed: goto err;
0
348 }-
349 tmpentry = NULL;-
350 }
executed 115545 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
115545
351-
352 /* Finally generate encoding */-
353 len = i2d_name_canon(intname, NULL);-
354 if (len < 0)
len < 0Description
TRUEnever evaluated
FALSEevaluated 36118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-36118
355 goto err;
never executed: goto err;
0
356 a->canon_enclen = len;-
357-
358 p = OPENSSL_malloc(a->canon_enclen);-
359 if (p == NULL) {
p == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 36118 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-36118
360 X509err(X509_F_X509_NAME_CANON, ERR_R_MALLOC_FAILURE);-
361 goto err;
never executed: goto err;
0
362 }-
363-
364 a->canon_enc = p;-
365-
366 i2d_name_canon(intname, &p);-
367-
368 ret = 1;-
369-
370 err:
code before this statement executed 36118 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
36118
371 X509_NAME_ENTRY_free(tmpentry);-
372 sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname,-
373 local_sk_X509_NAME_ENTRY_pop_free);-
374 return ret;
executed 40774 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
40774
375}-
376-
377/* Bitmap of all the types of string that will be canonicalized. */-
378-
379#define ASN1_MASK_CANON \-
380 (B_ASN1_UTF8STRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING \-
381 | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING \-
382 | B_ASN1_VISIBLESTRING)-
383-
384static int asn1_string_canon(ASN1_STRING *out, const ASN1_STRING *in)-
385{-
386 unsigned char *to, *from;-
387 int len, i;-
388-
389 /* If type not in bitmask just copy string across */-
390 if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) {
!(ASN1_tag2bit...010 | 0x0040))Description
TRUEevaluated 20492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 99709 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
20492-99709
391 if (!ASN1_STRING_copy(out, in))
!ASN1_STRING_copy(out, in)Description
TRUEnever evaluated
FALSEevaluated 20492 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-20492
392 return 0;
never executed: return 0;
0
393 return 1;
executed 20492 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
20492
394 }-
395-
396 out->type = V_ASN1_UTF8STRING;-
397 out->length = ASN1_STRING_to_UTF8(&out->data, in);-
398 if (out->length == -1)
out->length == -1Description
TRUEevaluated 4656 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 95053 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4656-95053
399 return 0;
executed 4656 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
4656
400-
401 to = out->data;-
402 from = to;-
403-
404 len = out->length;-
405-
406 /*-
407 * Convert string in place to canonical form. Ultimately we may need to-
408 * handle a wider range of characters but for now ignore anything with-
409 * MSB set and rely on the ossl_isspace() to fail on bad characters without-
410 * needing isascii or range checks as well.-
411 */-
412-
413 /* Ignore leading spaces */-
414 while (len > 0 && ossl_isspace(*from)) {
len > 0Description
TRUEevaluated 69703 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27527 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(ossl_ctype_ch...(*from), 0x8))Description
TRUEevaluated 2177 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 67526 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2177-69703
415 from++;-
416 len--;-
417 }
executed 2177 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2177
418-
419 to = from + len;-
420-
421 /* Ignore trailing spaces */-
422 while (len > 0 && ossl_isspace(to[-1])) {
len > 0Description
TRUEevaluated 68668 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 27527 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(ossl_ctype_ch...to[-1]), 0x8))Description
TRUEevaluated 1142 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 67526 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1142-68668
423 to--;-
424 len--;-
425 }
executed 1142 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1142
426-
427 to = out->data;-
428-
429 i = 0;-
430 while (i < len) {
i < lenDescription
TRUEevaluated 867351 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 95053 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
95053-867351
431 /* If not ASCII set just copy across */-
432 if (!ossl_isascii(*from)) {
!(((*from) & ~127) == 0)Description
TRUEevaluated 212781 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 654570 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
212781-654570
433 *to++ = *from++;-
434 i++;-
435 }
executed 212781 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
212781
436 /* Collapse multiple spaces */-
437 else if (ossl_isspace(*from)) {
(ossl_ctype_ch...(*from), 0x8))Description
TRUEevaluated 54920 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 599650 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
54920-599650
438 /* Copy one space across */-
439 *to++ = ' ';-
440 /*-
441 * Ignore subsequent spaces. Note: don't need to check len here-
442 * because we know the last character is a non-space so we can't-
443 * overflow.-
444 */-
445 do {-
446 from++;-
447 i++;-
448 }
executed 56267 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
56267
449 while (ossl_isspace(*from));
(ossl_ctype_ch...(*from), 0x8))Description
TRUEevaluated 1347 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 54920 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1347-54920
450 } else {
executed 54920 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
54920
451 *to++ = ossl_tolower(*from);-
452 from++;-
453 i++;-
454 }
executed 599650 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
599650
455 }-
456-
457 out->length = to - out->data;-
458-
459 return 1;
executed 95053 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
95053
460-
461}-
462-
463static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) * _intname,-
464 unsigned char **in)-
465{-
466 int i, len, ltmp;-
467 ASN1_VALUE *v;-
468 STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname;-
469-
470 len = 0;-
471 for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) {
i < sk_ASN1_VALUE_num(intname)Description
TRUEevaluated 150480 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 72236 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
72236-150480
472 v = sk_ASN1_VALUE_value(intname, i);-
473 ltmp = ASN1_item_ex_i2d(&v, in,-
474 ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1);-
475 if (ltmp < 0)
ltmp < 0Description
TRUEnever evaluated
FALSEevaluated 150480 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-150480
476 return ltmp;
never executed: return ltmp;
0
477 len += ltmp;-
478 }
executed 150480 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
150480
479 return len;
executed 72236 times by 1 test: return len;
Executed by:
  • libcrypto.so.1.1
72236
480}-
481-
482int X509_NAME_set(X509_NAME **xn, X509_NAME *name)-
483{-
484 if (*xn == name)
*xn == nameDescription
TRUEnever evaluated
FALSEevaluated 561 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-561
485 return *xn != NULL;
never executed: return *xn != ((void *)0) ;
0
486 if ((name = X509_NAME_dup(name)) == NULL)
(name = X509_N...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 561 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-561
487 return 0;
never executed: return 0;
0
488 X509_NAME_free(*xn);-
489 *xn = name;-
490 return 1;
executed 561 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
561
491}-
492-
493int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase)-
494{-
495 char *s, *c, *b;-
496 int l, i;-
497-
498 l = 80 - 2 - obase;-
499-
500 b = X509_NAME_oneline(name, NULL, 0);-
501 if (!b)
!bDescription
TRUEnever evaluated
FALSEevaluated 5796 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5796
502 return 0;
never executed: return 0;
0
503 if (!*b) {
!*bDescription
TRUEevaluated 4047 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1749 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1749-4047
504 OPENSSL_free(b);-
505 return 1;
executed 4047 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4047
506 }-
507 s = b + 1; /* skip the first slash */-
508-
509 c = s;-
510 for (;;) {-
511 if (((*s == '/') &&
(*s == '/')Description
TRUEevaluated 15616 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 308618 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
15616-308618
512 (ossl_isupper(s[1]) && ((s[2] == '=') ||
(ossl_ctype_ch...((s[1]), 0x2))Description
TRUEevaluated 4469 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11147 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(s[2] == '=')Description
TRUEevaluated 1348 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3121 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1348-11147
513 (ossl_isupper(s[2]) && (s[3] == '='))
(ossl_ctype_ch...((s[2]), 0x2))Description
TRUEevaluated 2457 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 664 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(s[3] == '=')Description
TRUEevaluated 1837 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 620 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
620-2457
514 ))) || (*s == '\0'))
(*s == '\0')Description
TRUEevaluated 1749 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 319300 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1749-319300
515 {-
516 i = s - c;-
517 if (BIO_write(bp, c, i) != i)
BIO_write(bp, c, i) != iDescription
TRUEnever evaluated
FALSEevaluated 4934 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4934
518 goto err;
never executed: goto err;
0
519 c = s + 1; /* skip following slash */-
520 if (*s != '\0') {
*s != '\0'Description
TRUEevaluated 3185 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1749 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1749-3185
521 if (BIO_write(bp, ", ", 2) != 2)
BIO_write(bp, ", ", 2) != 2Description
TRUEnever evaluated
FALSEevaluated 3185 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-3185
522 goto err;
never executed: goto err;
0
523 }
executed 3185 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
3185
524 l--;-
525 }
executed 4934 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4934
526 if (*s == '\0')
*s == '\0'Description
TRUEevaluated 1749 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 322485 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1749-322485
527 break;
executed 1749 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
1749
528 s++;-
529 l--;-
530 }
executed 322485 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
322485
531-
532 OPENSSL_free(b);-
533 return 1;
executed 1749 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1749
534 err:-
535 X509err(X509_F_X509_NAME_PRINT, ERR_R_BUF_LIB);-
536 OPENSSL_free(b);-
537 return 0;
never executed: return 0;
0
538}-
539-
540int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder,-
541 size_t *pderlen)-
542{-
543 /* Make sure encoding is valid */-
544 if (i2d_X509_NAME(nm, NULL) <= 0)
i2d_X509_NAME(...id *)0) ) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
545 return 0;
never executed: return 0;
0
546 if (pder != NULL)
pder != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
547 *pder = (unsigned char *)nm->bytes->data;
never executed: *pder = (unsigned char *)nm->bytes->data;
0
548 if (pderlen != NULL)
pderlen != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
549 *pderlen = nm->bytes->length;
never executed: *pderlen = nm->bytes->length;
0
550 return 1;
never executed: return 1;
0
551}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2