OpenCoverage

x509_v3.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509/x509_v3.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/cryptlib.h"-
12#include <openssl/safestack.h>-
13#include <openssl/asn1.h>-
14#include <openssl/objects.h>-
15#include <openssl/evp.h>-
16#include <openssl/x509.h>-
17#include <openssl/x509v3.h>-
18#include "x509_lcl.h"-
19-
20int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)-
21{-
22 if (x == NULL)
x == ((void *)0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 63895 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
8-63895
23 return 0;
executed 8 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
8
24 return sk_X509_EXTENSION_num(x);
executed 63895 times by 1 test: return sk_X509_EXTENSION_num(x);
Executed by:
  • libcrypto.so.1.1
63895
25}-
26-
27int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid,-
28 int lastpos)-
29{-
30 ASN1_OBJECT *obj;-
31-
32 obj = OBJ_nid2obj(nid);-
33 if (obj == NULL)
obj == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 203 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-203
34 return -2;
never executed: return -2;
0
35 return X509v3_get_ext_by_OBJ(x, obj, lastpos);
executed 203 times by 1 test: return X509v3_get_ext_by_OBJ(x, obj, lastpos);
Executed by:
  • libcrypto.so.1.1
203
36}-
37-
38int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk,-
39 const ASN1_OBJECT *obj, int lastpos)-
40{-
41 int n;-
42 X509_EXTENSION *ex;-
43-
44 if (sk == NULL)
sk == ((void *)0)Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 100 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
100-103
45 return -1;
executed 103 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
103
46 lastpos++;-
47 if (lastpos < 0)
lastpos < 0Description
TRUEnever evaluated
FALSEevaluated 100 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-100
48 lastpos = 0;
never executed: lastpos = 0;
0
49 n = sk_X509_EXTENSION_num(sk);-
50 for (; lastpos < n; lastpos++) {
lastpos < nDescription
TRUEevaluated 419 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 65 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
65-419
51 ex = sk_X509_EXTENSION_value(sk, lastpos);-
52 if (OBJ_cmp(ex->object, obj) == 0)
OBJ_cmp(ex->object, obj) == 0Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 384 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
35-384
53 return lastpos;
executed 35 times by 1 test: return lastpos;
Executed by:
  • libcrypto.so.1.1
35
54 }
executed 384 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
384
55 return -1;
executed 65 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
65
56}-
57-
58int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,-
59 int lastpos)-
60{-
61 int n;-
62 X509_EXTENSION *ex;-
63-
64 if (sk == NULL)
sk == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
65 return -1;
never executed: return -1;
0
66 lastpos++;-
67 if (lastpos < 0)
lastpos < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
68 lastpos = 0;
never executed: lastpos = 0;
0
69 n = sk_X509_EXTENSION_num(sk);-
70 for (; lastpos < n; lastpos++) {
lastpos < nDescription
TRUEnever evaluated
FALSEnever evaluated
0
71 ex = sk_X509_EXTENSION_value(sk, lastpos);-
72 if (((ex->critical > 0) && crit) || ((ex->critical <= 0) && !crit))
(ex->critical > 0)Description
TRUEnever evaluated
FALSEnever evaluated
critDescription
TRUEnever evaluated
FALSEnever evaluated
(ex->critical <= 0)Description
TRUEnever evaluated
FALSEnever evaluated
!critDescription
TRUEnever evaluated
FALSEnever evaluated
0
73 return lastpos;
never executed: return lastpos;
0
74 }
never executed: end of block
0
75 return -1;
never executed: return -1;
0
76}-
77-
78X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc)-
79{-
80 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 67079 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
sk_X509_EXTENS..._num(x) <= locDescription
TRUEnever evaluated
FALSEevaluated 67079 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
loc < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 67078 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-67079
81 return NULL;
executed 1 time by 1 test: return ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
1
82 else-
83 return sk_X509_EXTENSION_value(x, loc);
executed 67078 times by 1 test: return sk_X509_EXTENSION_value(x, loc);
Executed by:
  • libcrypto.so.1.1
67078
84}-
85-
86X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc)-
87{-
88 X509_EXTENSION *ret;-
89-
90 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
sk_X509_EXTENS..._num(x) <= locDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
loc < 0Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9
91 return NULL;
never executed: return ((void *)0) ;
0
92 ret = sk_X509_EXTENSION_delete(x, loc);-
93 return ret;
executed 9 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
9
94}-
95-
96STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,-
97 X509_EXTENSION *ex, int loc)-
98{-
99 X509_EXTENSION *new_ex = NULL;-
100 int n;-
101 STACK_OF(X509_EXTENSION) *sk = NULL;-
102-
103 if (x == NULL) {
x == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-35
104 X509err(X509_F_X509V3_ADD_EXT, ERR_R_PASSED_NULL_PARAMETER);-
105 goto err2;
never executed: goto err2;
0
106 }-
107-
108 if (*x == NULL) {
*x == ((void *)0)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-26
109 if ((sk = sk_X509_EXTENSION_new_null()) == NULL)
(sk = sk_X509_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-9
110 goto err;
never executed: goto err;
0
111 } else
executed 9 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9
112 sk = *x;
executed 26 times by 1 test: sk = *x;
Executed by:
  • libcrypto.so.1.1
26
113-
114 n = sk_X509_EXTENSION_num(sk);-
115 if (loc > n)
loc > nDescription
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-35
116 loc = n;
never executed: loc = n;
0
117 else if (loc < 0)
loc < 0Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-35
118 loc = n;
executed 35 times by 1 test: loc = n;
Executed by:
  • libcrypto.so.1.1
35
119-
120 if ((new_ex = X509_EXTENSION_dup(ex)) == NULL)
(new_ex = X509...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-35
121 goto err2;
never executed: goto err2;
0
122 if (!sk_X509_EXTENSION_insert(sk, new_ex, loc))
!sk_X509_EXTEN..., new_ex, loc)Description
TRUEnever evaluated
FALSEevaluated 35 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-35
123 goto err;
never executed: goto err;
0
124 if (*x == NULL)
*x == ((void *)0)Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 26 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-26
125 *x = sk;
executed 9 times by 1 test: *x = sk;
Executed by:
  • libcrypto.so.1.1
9
126 return sk;
executed 35 times by 1 test: return sk;
Executed by:
  • libcrypto.so.1.1
35
127 err:-
128 X509err(X509_F_X509V3_ADD_EXT, ERR_R_MALLOC_FAILURE);-
129 err2:
code before this statement never executed: err2:
0
130 X509_EXTENSION_free(new_ex);-
131 if (x != NULL && *x == NULL)
x != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
*x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
132 sk_X509_EXTENSION_free(sk);
never executed: sk_X509_EXTENSION_free(sk);
0
133 return NULL;
never executed: return ((void *)0) ;
0
134}-
135-
136X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,-
137 int crit,-
138 ASN1_OCTET_STRING *data)-
139{-
140 ASN1_OBJECT *obj;-
141 X509_EXTENSION *ret;-
142-
143 obj = OBJ_nid2obj(nid);-
144 if (obj == NULL) {
obj == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
145 X509err(X509_F_X509_EXTENSION_CREATE_BY_NID, X509_R_UNKNOWN_NID);-
146 return NULL;
never executed: return ((void *)0) ;
0
147 }-
148 ret = X509_EXTENSION_create_by_OBJ(ex, obj, crit, data);-
149 if (ret == NULL)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
150 ASN1_OBJECT_free(obj);
never executed: ASN1_OBJECT_free(obj);
0
151 return ret;
executed 221 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
221
152}-
153-
154X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,-
155 const ASN1_OBJECT *obj, int crit,-
156 ASN1_OCTET_STRING *data)-
157{-
158 X509_EXTENSION *ret;-
159-
160 if ((ex == NULL) || (*ex == NULL)) {
(ex == ((void *)0) )Description
TRUEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(*ex == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0-221
161 if ((ret = X509_EXTENSION_new()) == NULL) {
(ret = X509_EX...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
162 X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ,-
163 ERR_R_MALLOC_FAILURE);-
164 return NULL;
never executed: return ((void *)0) ;
0
165 }-
166 } else
executed 221 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
221
167 ret = *ex;
never executed: ret = *ex;
0
168-
169 if (!X509_EXTENSION_set_object(ret, obj))
!X509_EXTENSIO...ject(ret, obj)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
170 goto err;
never executed: goto err;
0
171 if (!X509_EXTENSION_set_critical(ret, crit))
!X509_EXTENSIO...cal(ret, crit)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
172 goto err;
never executed: goto err;
0
173 if (!X509_EXTENSION_set_data(ret, data))
!X509_EXTENSIO...ata(ret, data)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
174 goto err;
never executed: goto err;
0
175-
176 if ((ex != NULL) && (*ex == NULL))
(ex != ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(*ex == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
0-221
177 *ex = ret;
never executed: *ex = ret;
0
178 return ret;
executed 221 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
221
179 err:-
180 if ((ex == NULL) || (ret != *ex))
(ex == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
(ret != *ex)Description
TRUEnever evaluated
FALSEnever evaluated
0
181 X509_EXTENSION_free(ret);
never executed: X509_EXTENSION_free(ret);
0
182 return NULL;
never executed: return ((void *)0) ;
0
183}-
184-
185int X509_EXTENSION_set_object(X509_EXTENSION *ex, const ASN1_OBJECT *obj)-
186{-
187 if ((ex == NULL) || (obj == NULL))
(ex == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(obj == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
188 return 0;
never executed: return 0;
0
189 ASN1_OBJECT_free(ex->object);-
190 ex->object = OBJ_dup(obj);-
191 return ex->object != NULL;
executed 221 times by 1 test: return ex->object != ((void *)0) ;
Executed by:
  • libcrypto.so.1.1
221
192}-
193-
194int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit)-
195{-
196 if (ex == NULL)
ex == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
197 return 0;
never executed: return 0;
0
198 ex->critical = (crit) ? 0xFF : -1;
(crit)Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 196 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
25-196
199 return 1;
executed 221 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
221
200}-
201-
202int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)-
203{-
204 int i;-
205-
206 if (ex == NULL)
ex == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
207 return 0;
never executed: return 0;
0
208 i = ASN1_OCTET_STRING_set(&ex->value, data->data, data->length);-
209 if (!i)
!iDescription
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-221
210 return 0;
never executed: return 0;
0
211 return 1;
executed 221 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
221
212}-
213-
214ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex)-
215{-
216 if (ex == NULL)
ex == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1348619 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1348619
217 return NULL;
never executed: return ((void *)0) ;
0
218 return ex->object;
executed 1348619 times by 1 test: return ex->object;
Executed by:
  • libcrypto.so.1.1
1348619
219}-
220-
221ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex)-
222{-
223 if (ex == NULL)
ex == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 259722 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-259722
224 return NULL;
never executed: return ((void *)0) ;
0
225 return &ex->value;
executed 259722 times by 1 test: return &ex->value;
Executed by:
  • libcrypto.so.1.1
259722
226}-
227-
228int X509_EXTENSION_get_critical(const X509_EXTENSION *ex)-
229{-
230 if (ex == NULL)
ex == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 230983 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-230983
231 return 0;
never executed: return 0;
0
232 if (ex->critical > 0)
ex->critical > 0Description
TRUEevaluated 20921 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 210062 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
20921-210062
233 return 1;
executed 20921 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
20921
234 return 0;
executed 210062 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
210062
235}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2