OpenCoverage

async_wait.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/async/async_wait.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2016-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/* This must be the first #include file */-
11#include "async_locl.h"-
12-
13#include <openssl/err.h>-
14-
15ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void)-
16{-
17 return OPENSSL_zalloc(sizeof(ASYNC_WAIT_CTX));
executed 5 times by 1 test: return CRYPTO_zalloc(sizeof(ASYNC_WAIT_CTX), __FILE__, 17);
Executed by:
  • libcrypto.so.1.1
5
18}-
19-
20void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx)-
21{-
22 struct fd_lookup_st *curr;-
23 struct fd_lookup_st *next;-
24-
25 if (ctx == NULL)
ctx == ((void *)0)Description
TRUEevaluated 8254 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-8254
26 return;
executed 8254 times by 1 test: return;
Executed by:
  • libcrypto.so.1.1
8254
27-
28 curr = ctx->fds;-
29 while (curr != NULL) {
curr != ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
30 if (!curr->del) {
!curr->delDescription
TRUEnever evaluated
FALSEnever evaluated
0
31 /* Only try and cleanup if it hasn't been marked deleted */-
32 if (curr->cleanup != NULL)
curr->cleanup != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
33 curr->cleanup(ctx, curr->key, curr->fd, curr->custom_data);
never executed: curr->cleanup(ctx, curr->key, curr->fd, curr->custom_data);
0
34 }
never executed: end of block
0
35 /* Always free the fd_lookup_st */-
36 next = curr->next;-
37 OPENSSL_free(curr);-
38 curr = next;-
39 }
never executed: end of block
0
40-
41 OPENSSL_free(ctx);-
42}
executed 5 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
5
43int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,-
44 OSSL_ASYNC_FD fd, void *custom_data,-
45 void (*cleanup)(ASYNC_WAIT_CTX *, const void *,-
46 OSSL_ASYNC_FD, void *))-
47{-
48 struct fd_lookup_st *fdlookup;-
49-
50 if ((fdlookup = OPENSSL_zalloc(sizeof(*fdlookup))) == NULL) {
(fdlookup = CR...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
51 ASYNCerr(ASYNC_F_ASYNC_WAIT_CTX_SET_WAIT_FD, ERR_R_MALLOC_FAILURE);-
52 return 0;
never executed: return 0;
0
53 }-
54-
55 fdlookup->key = key;-
56 fdlookup->fd = fd;-
57 fdlookup->custom_data = custom_data;-
58 fdlookup->cleanup = cleanup;-
59 fdlookup->add = 1;-
60 fdlookup->next = ctx->fds;-
61 ctx->fds = fdlookup;-
62 ctx->numadd++;-
63 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
64}-
65-
66int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key,-
67 OSSL_ASYNC_FD *fd, void **custom_data)-
68{-
69 struct fd_lookup_st *curr;-
70-
71 curr = ctx->fds;-
72 while (curr != NULL) {
curr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
73 if (curr->del) {
curr->delDescription
TRUEnever evaluated
FALSEnever evaluated
0
74 /* This one has been marked deleted so do nothing */-
75 curr = curr->next;-
76 continue;
never executed: continue;
0
77 }-
78 if (curr->key == key) {
curr->key == keyDescription
TRUEnever evaluated
FALSEnever evaluated
0
79 *fd = curr->fd;-
80 *custom_data = curr->custom_data;-
81 return 1;
never executed: return 1;
0
82 }-
83 curr = curr->next;-
84 }
never executed: end of block
0
85 return 0;
never executed: return 0;
0
86}-
87-
88int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd,-
89 size_t *numfds)-
90{-
91 struct fd_lookup_st *curr;-
92-
93 curr = ctx->fds;-
94 *numfds = 0;-
95 while (curr != NULL) {
curr != ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
3-5
96 if (curr->del) {
curr->delDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-2
97 /* This one has been marked deleted so do nothing */-
98 curr = curr->next;-
99 continue;
executed 1 time by 1 test: continue;
Executed by:
  • libcrypto.so.1.1
1
100 }-
101 if (fd != NULL) {
fd != ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1
102 *fd = curr->fd;-
103 fd++;-
104 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
105 (*numfds)++;-
106 curr = curr->next;-
107 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
108 return 1;
executed 5 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
5
109}-
110-
111int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd,-
112 size_t *numaddfds, OSSL_ASYNC_FD *delfd,-
113 size_t *numdelfds)-
114{-
115 struct fd_lookup_st *curr;-
116-
117 *numaddfds = ctx->numadd;-
118 *numdelfds = ctx->numdel;-
119 if (addfd == NULL && delfd == NULL)
addfd == ((void *)0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
delfd == ((void *)0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-5
120 return 1;
executed 4 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
4
121-
122 curr = ctx->fds;-
123-
124 while (curr != NULL) {
curr != ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2
125 /* We ignore fds that have been marked as both added and deleted */-
126 if (curr->del && !curr->add && (delfd != NULL)) {
curr->delDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
!curr->addDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(delfd != ((void *)0) )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
127 *delfd = curr->fd;-
128 delfd++;-
129 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
130 if (curr->add && !curr->del && (addfd != NULL)) {
curr->addDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
!curr->delDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(addfd != ((void *)0) )Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
131 *addfd = curr->fd;-
132 addfd++;-
133 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
134 curr = curr->next;-
135 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
136-
137 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
138}-
139-
140int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key)-
141{-
142 struct fd_lookup_st *curr, *prev;-
143-
144 curr = ctx->fds;-
145 prev = NULL;-
146 while (curr != NULL) {
curr != ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
147 if (curr->del == 1) {
curr->del == 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
148 /* This one has been marked deleted already so do nothing */-
149 prev = curr;-
150 curr = curr->next;-
151 continue;
never executed: continue;
0
152 }-
153 if (curr->key == key) {
curr->key == keyDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
154 /* If fd has just been added, remove it from the list */-
155 if (curr->add == 1) {
curr->add == 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1
156 if (ctx->fds == curr) {
ctx->fds == currDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
157 ctx->fds = curr->next;-
158 } else {
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
159 prev->next = curr->next;-
160 }
never executed: end of block
0
161-
162 /* It is responsibility of the caller to cleanup before calling-
163 * ASYNC_WAIT_CTX_clear_fd-
164 */-
165 OPENSSL_free(curr);-
166 ctx->numadd--;-
167 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
168 }-
169-
170 /*-
171 * Mark it as deleted. We don't call cleanup if explicitly asked-
172 * to clear an fd. We assume the caller is going to do that (if-
173 * appropriate).-
174 */-
175 curr->del = 1;-
176 ctx->numdel++;-
177 return 1;
executed 1 time by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1
178 }-
179 prev = curr;-
180 curr = curr->next;-
181 }
never executed: end of block
0
182 return 0;
never executed: return 0;
0
183}-
184-
185void async_wait_ctx_reset_counts(ASYNC_WAIT_CTX *ctx)-
186{-
187 struct fd_lookup_st *curr, *prev = NULL;-
188-
189 ctx->numadd = 0;-
190 ctx->numdel = 0;-
191-
192 curr = ctx->fds;-
193-
194 while (curr != NULL) {
curr != ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-9
195 if (curr->del) {
curr->delDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1
196 if (prev == NULL)
prev == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
197 ctx->fds = curr->next;
executed 1 time by 1 test: ctx->fds = curr->next;
Executed by:
  • libcrypto.so.1.1
1
198 else-
199 prev->next = curr->next;
never executed: prev->next = curr->next;
0
200 OPENSSL_free(curr);-
201 if (prev == NULL)
prev == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
202 curr = ctx->fds;
executed 1 time by 1 test: curr = ctx->fds;
Executed by:
  • libcrypto.so.1.1
1
203 else-
204 curr = prev->next;
never executed: curr = prev->next;
0
205 continue;
executed 1 time by 1 test: continue;
Executed by:
  • libcrypto.so.1.1
1
206 }-
207 if (curr->add) {
curr->addDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
208 curr->add = 0;-
209 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
210 prev = curr;-
211 curr = curr->next;-
212 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
213}
executed 9 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2