OpenCoverage

eng_table.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/engine/eng_table.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4struct st_engine_pile {-
5-
6 int nid;-
7-
8 struct stack_st_ENGINE *sk;-
9-
10 ENGINE *funct;-
11-
12-
13-
14 int uptodate;-
15};-
16-
17-
18struct st_engine_table {-
19 struct lhash_st_ENGINE_PILE piles;-
20};-
21-
22typedef struct st_engine_pile_doall {-
23 engine_table_doall_cb *cb;-
24 void *arg;-
25} ENGINE_PILE_DOALL;-
26-
27-
28static unsigned int table_flags = 0;-
29-
30-
31unsigned int ENGINE_get_table_flags(void)-
32{-
33 return
never executed: return table_flags;
table_flags;
never executed: return table_flags;
0
34}-
35-
36void ENGINE_set_table_flags(unsigned int flags)-
37{-
38 table_flags = flags;-
39}
never executed: end of block
0
40-
41-
42static unsigned long engine_pile_hash(const ENGINE_PILE *c)-
43{-
44 return
executed 20857 times by 1 test: return c->nid;
Executed by:
  • libcrypto.so.1.1
c->nid;
executed 20857 times by 1 test: return c->nid;
Executed by:
  • libcrypto.so.1.1
20857
45}-
46-
47static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b)-
48{-
49 return
executed 14801 times by 1 test: return a->nid - b->nid;
Executed by:
  • libcrypto.so.1.1
a->nid - b->nid;
executed 14801 times by 1 test: return a->nid - b->nid;
Executed by:
  • libcrypto.so.1.1
14801
50}-
51-
52static int int_table_check(ENGINE_TABLE **t, int create)-
53{-
54 struct lhash_st_ENGINE_PILE *lh;-
55-
56 if (*
*tDescription
TRUEevaluated 12049 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
t
*tDescription
TRUEevaluated 12049 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
1101-12049
57 return
executed 12049 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 12049 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
12049
58 if (!create
!createDescription
TRUEnever evaluated
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-1101
59 return
never executed: return 0;
0;
never executed: return 0;
0
60 if ((
(lh = lh_ENGIN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
lh = lh_ENGINE_PILE_new(engine_pile_hash, engine_pile_cmp)) ==
(lh = lh_ENGIN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1101
61 ((void *)0)
(lh = lh_ENGIN...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1101
62 )-
63 return
never executed: return 0;
0;
never executed: return 0;
0
64 *t = (ENGINE_TABLE *)lh;-
65 return
executed 1101 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 1101 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1101
66}-
67-
68-
69-
70-
71-
72int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,-
73 ENGINE *e, const int *nids, int num_nids,-
74 int setdefault)-
75{-
76 int ret = 0, added = 0;-
77 ENGINE_PILE tmplate, *fnd;-
78 CRYPTO_THREAD_write_lock(global_engine_lock);-
79 if (!(*table)
!(*table)Description
TRUEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-1101
80 added = 1;
executed 1101 times by 1 test: added = 1;
Executed by:
  • libcrypto.so.1.1
1101
81 if (!int_table_check(table, 1)
!int_table_check(table, 1)Description
TRUEnever evaluated
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-1101
82 goto
never executed: goto end;
end;
never executed: goto end;
0
83 if (added
addedDescription
TRUEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-1101
84-
85 engine_cleanup_add_first(cleanup);
executed 1101 times by 1 test: engine_cleanup_add_first(cleanup);
Executed by:
  • libcrypto.so.1.1
1101
86 while (num_nids--
num_nids--Description
TRUEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
1101-2936
87 tmplate.nid = *nids;-
88 fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);-
89 if (!fnd
!fndDescription
TRUEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-2936
90 fnd = CRYPTO_malloc(sizeof(*fnd), __FILE__, 100);-
91 if (fnd ==
fnd == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2936
92 ((void *)0)
fnd == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2936
93 )-
94 goto
never executed: goto end;
end;
never executed: goto end;
0
95 fnd->uptodate = 1;-
96 fnd->nid = *nids;-
97 fnd->sk = sk_ENGINE_new_null();-
98 if (!fnd->sk
!fnd->skDescription
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-2936
99 CRYPTO_free(fnd, __FILE__, 107);-
100 goto
never executed: goto end;
end;
never executed: goto end;
0
101 }-
102 fnd->funct = -
103 ((void *)0)-
104 ;-
105 (void)lh_ENGINE_PILE_insert(&(*table)->piles, fnd);-
106 if (lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate) != fnd
lh_ENGINE_PILE...mplate) != fndDescription
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-2936
107 sk_ENGINE_free(fnd->sk);-
108 CRYPTO_free(fnd, __FILE__, 114);-
109 goto
never executed: goto end;
end;
never executed: goto end;
0
110 }-
111 }
executed 2936 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2936
112-
113 (void)sk_ENGINE_delete_ptr(fnd->sk, e);-
114-
115-
116-
117 if (!sk_ENGINE_push(fnd->sk, e)
!sk_ENGINE_push(fnd->sk, e)Description
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-2936
118 goto
never executed: goto end;
end;
never executed: goto end;
0
119-
120 fnd->uptodate = 0;-
121 if (setdefault
setdefaultDescription
TRUEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-2936
122 if (!engine_unlocked_init(e)
!engine_unlocked_init(e)Description
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-2936
123 ERR_put_error(38,(184),(109),__FILE__,130)-
124 ;-
125 goto
never executed: goto end;
end;
never executed: goto end;
0
126 }-
127 if (fnd->funct
fnd->functDescription
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-2936
128 engine_unlocked_finish(fnd->funct, 0);
never executed: engine_unlocked_finish(fnd->funct, 0);
0
129 fnd->funct = e;-
130 fnd->uptodate = 1;-
131 }
executed 2936 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2936
132 nids++;-
133 }
executed 2936 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2936
134 ret = 1;-
135 end:
code before this statement executed 1101 times by 1 test: end:
Executed by:
  • libcrypto.so.1.1
1101
136 CRYPTO_THREAD_unlock(global_engine_lock);-
137 return
executed 1101 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 1101 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
1101
138}-
139-
140static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)-
141{-
142 int n;-
143-
144 while ((
(n = sk_ENGINE...->sk, e)) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
n = sk_ENGINE_find(pile->sk, e)) >= 0
(n = sk_ENGINE...->sk, e)) >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
145 (void)sk_ENGINE_delete(pile->sk, n);-
146 pile->uptodate = 0;-
147 }
never executed: end of block
0
148 if (pile->funct == e
pile->funct == eDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
149 engine_unlocked_finish(e, 0);-
150 pile->funct = -
151 ((void *)0)-
152 ;-
153 }
never executed: end of block
0
154}
never executed: end of block
0
155-
156static inline void lh_ENGINE_PILE_doall_ENGINE(struct lhash_st_ENGINE_PILE *lh, void (*fn)(ENGINE_PILE *, ENGINE *), ENGINE *arg) { OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); }
never executed: end of block
struct lhash_st_ENGINE_PILE;
0
157-
158void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e)-
159{-
160 CRYPTO_THREAD_write_lock(global_engine_lock);-
161 if (int_table_check(table, 0)
int_table_check(table, 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
162 lh_ENGINE_PILE_doall_ENGINE(&(*table)->piles, int_unregister_cb, e);
never executed: lh_ENGINE_PILE_doall_ENGINE(&(*table)->piles, int_unregister_cb, e);
0
163 CRYPTO_THREAD_unlock(global_engine_lock);-
164}
never executed: end of block
0
165-
166static void int_cleanup_cb_doall(ENGINE_PILE *p)-
167{-
168 if (!p
!pDescription
TRUEnever evaluated
FALSEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-2936
169 return;
never executed: return;
0
170 sk_ENGINE_free(p->sk);-
171 if (p->funct
p->functDescription
TRUEevaluated 2936 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-2936
172 engine_unlocked_finish(p->funct, 0);
executed 2936 times by 1 test: engine_unlocked_finish(p->funct, 0);
Executed by:
  • libcrypto.so.1.1
2936
173 CRYPTO_free(p, __FILE__, 177);-
174}
executed 2936 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2936
175-
176void engine_table_cleanup(ENGINE_TABLE **table)-
177{-
178 CRYPTO_THREAD_write_lock(global_engine_lock);-
179 if (*
*tableDescription
TRUEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
table
*tableDescription
TRUEevaluated 1101 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-1101
180 lh_ENGINE_PILE_doall(&(*table)->piles, int_cleanup_cb_doall);-
181 lh_ENGINE_PILE_free(&(*table)->piles);-
182 *table = -
183 ((void *)0)-
184 ;-
185 }
executed 1101 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1101
186 CRYPTO_THREAD_unlock(global_engine_lock);-
187}
executed 1101 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1101
188-
189-
190-
191ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)-
192-
193-
194-
195-
196{-
197 ENGINE *ret = -
198 ((void *)0)-
199 ;-
200 ENGINE_PILE tmplate, *fnd = -
201 ((void *)0)-
202 ;-
203 int initres, loop = 0;-
204-
205 if (!(*table)
!(*table)Description
TRUEevaluated 4142606 times by 3 tests
Evaluated by:
  • curve448_internal_test
  • libcrypto.so.1.1
  • sm2_internal_test
FALSEevaluated 12049 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
12049-4142606
206-
207-
208-
209-
210 return
executed 4141226 times by 3 tests: return ((void *)0) ;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
  • sm2_internal_test
executed 4141226 times by 3 tests: return ((void *)0) ;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
  • sm2_internal_test
4141226
211 ((void *)0)
executed 4141226 times by 3 tests: return ((void *)0) ;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
  • sm2_internal_test
4141226
212 ;
executed 4141226 times by 3 tests: return ((void *)0) ;
Executed by:
  • curve448_internal_test
  • libcrypto.so.1.1
  • sm2_internal_test
4141226
213 }-
214 ERR_set_mark();-
215 CRYPTO_THREAD_write_lock(global_engine_lock);-
216-
217-
218-
219-
220 if (!int_table_check(table, 0)
!int_table_check(table, 0)Description
TRUEnever evaluated
FALSEevaluated 12049 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-12049
221 goto
never executed: goto end;
end;
never executed: goto end;
0
222 tmplate.nid = nid;-
223 fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);-
224 if (!fnd
!fndDescription
TRUEevaluated 184 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11865 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
184-11865
225 goto
executed 184 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
end;
executed 184 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
184
226 if (fnd->funct
fnd->functDescription
TRUEevaluated 11865 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
&& engine_unlocked_init(fnd->funct)
engine_unlocke...it(fnd->funct)Description
TRUEevaluated 11865 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
) {
0-11865
227-
228-
229-
230-
231 ret = fnd->funct;-
232 goto
executed 11865 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
end;
executed 11865 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
11865
233 }-
234 if (fnd->uptodate
fnd->uptodateDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
235 ret = fnd->funct;-
236 goto
never executed: goto end;
end;
never executed: goto end;
0
237 }-
238 trynext:
code before this statement never executed: trynext:
0
239 ret = sk_ENGINE_value(fnd->sk, loop++);-
240 if (!ret
!retDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
241-
242-
243-
244-
245 goto
never executed: goto end;
end;
never executed: goto end;
0
246 }-
247-
248 if ((
(ret->funct_ref > 0)Description
TRUEnever evaluated
FALSEnever evaluated
ret->funct_ref > 0)
(ret->funct_ref > 0)Description
TRUEnever evaluated
FALSEnever evaluated
|| !(table_flags & (unsigned int)0x0001)
!(table_flags ...ed int)0x0001)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
249 initres = engine_unlocked_init(ret);
never executed: initres = engine_unlocked_init(ret);
0
250 else-
251 initres = 0;
never executed: initres = 0;
0
252 if (initres
initresDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
253-
254 if ((
(fnd->funct != ret)Description
TRUEnever evaluated
FALSEnever evaluated
fnd->funct != ret)
(fnd->funct != ret)Description
TRUEnever evaluated
FALSEnever evaluated
&& engine_unlocked_init(ret)
engine_unlocked_init(ret)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
255-
256 if (fnd->funct
fnd->functDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
257 engine_unlocked_finish(fnd->funct, 0);
never executed: engine_unlocked_finish(fnd->funct, 0);
0
258 fnd->funct = ret;-
259-
260-
261-
262-
263 }
never executed: end of block
0
264-
265-
266-
267-
268 goto
never executed: goto end;
end;
never executed: goto end;
0
269 }-
270 goto
never executed: goto trynext;
trynext;
never executed: goto trynext;
0
271 end:-
272-
273-
274-
275-
276 if (fnd
fndDescription
TRUEevaluated 11865 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 184 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
184-11865
277 fnd->uptodate = 1;
executed 11865 times by 1 test: fnd->uptodate = 1;
Executed by:
  • libcrypto.so.1.1
11865
278 CRYPTO_THREAD_unlock(global_engine_lock);-
279-
280-
281-
282-
283 ERR_pop_to_mark();-
284 return
executed 12049 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 12049 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
12049
285}-
286-
287-
288-
289static void int_dall(const ENGINE_PILE *pile, ENGINE_PILE_DOALL *dall)-
290{-
291 dall->cb(pile->nid, pile->sk, pile->funct, dall->arg);-
292}
never executed: end of block
0
293-
294static inline void lh_ENGINE_PILE_doall_ENGINE_PILE_DOALL(struct lhash_st_ENGINE_PILE *lh, void (*fn)(const ENGINE_PILE *, ENGINE_PILE_DOALL *), ENGINE_PILE_DOALL *arg) { OPENSSL_LH_doall_arg((OPENSSL_LHASH *)lh, (OPENSSL_LH_DOALL_FUNCARG)fn, (void *)arg); }
never executed: end of block
struct lhash_st_ENGINE_PILE;
0
295-
296void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb,-
297 void *arg)-
298{-
299 ENGINE_PILE_DOALL dall;-
300 dall.cb = cb;-
301 dall.arg = arg;-
302 if (table
tableDescription
TRUEnever evaluated
FALSEevaluated 9796 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-9796
303 lh_ENGINE_PILE_doall_ENGINE_PILE_DOALL(&table->piles, int_dall, &dall);
never executed: lh_ENGINE_PILE_doall_ENGINE_PILE_DOALL(&table->piles, int_dall, &dall);
0
304}
executed 9796 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9796
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2