Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/async/async_wait.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | - | |||||||||||||||||||
15 | ASYNC_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:
| 5 | ||||||||||||||||||
18 | } | - | ||||||||||||||||||
19 | - | |||||||||||||||||||
20 | void 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)
| 5-8254 | ||||||||||||||||||
26 | return; executed 8254 times by 1 test: return; Executed by:
| 8254 | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | curr = ctx->fds; | - | ||||||||||||||||||
29 | while (curr != NULL) {
| 0-5 | ||||||||||||||||||
30 | if (!curr->del) {
| 0 | ||||||||||||||||||
31 | /* Only try and cleanup if it hasn't been marked deleted */ | - | ||||||||||||||||||
32 | if (curr->cleanup != NULL)
| 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:
| 5 | ||||||||||||||||||
43 | int 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) {
| 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:
| 2 | ||||||||||||||||||
64 | } | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | int 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) {
| 0 | ||||||||||||||||||
73 | if (curr->del) {
| 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) {
| 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 | - | |||||||||||||||||||
88 | int 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) {
| 3-5 | ||||||||||||||||||
96 | if (curr->del) {
| 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:
| 1 | ||||||||||||||||||
100 | } | - | ||||||||||||||||||
101 | if (fd != NULL) {
| 1 | ||||||||||||||||||
102 | *fd = curr->fd; | - | ||||||||||||||||||
103 | fd++; | - | ||||||||||||||||||
104 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
105 | (*numfds)++; | - | ||||||||||||||||||
106 | curr = curr->next; | - | ||||||||||||||||||
107 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
108 | return 1; executed 5 times by 1 test: return 1; Executed by:
| 5 | ||||||||||||||||||
109 | } | - | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | int 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)
| 1-5 | ||||||||||||||||||
120 | return 1; executed 4 times by 1 test: return 1; Executed by:
| 4 | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | curr = ctx->fds; | - | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | while (curr != NULL) {
| 2 | ||||||||||||||||||
125 | /* We ignore fds that have been marked as both added and deleted */ | - | ||||||||||||||||||
126 | if (curr->del && !curr->add && (delfd != NULL)) {
| 0-1 | ||||||||||||||||||
127 | *delfd = curr->fd; | - | ||||||||||||||||||
128 | delfd++; | - | ||||||||||||||||||
129 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
130 | if (curr->add && !curr->del && (addfd != NULL)) {
| 0-1 | ||||||||||||||||||
131 | *addfd = curr->fd; | - | ||||||||||||||||||
132 | addfd++; | - | ||||||||||||||||||
133 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
134 | curr = curr->next; | - | ||||||||||||||||||
135 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | return 1; executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||||||||||||||
138 | } | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | int 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) {
| 0-2 | ||||||||||||||||||
147 | if (curr->del == 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) {
| 0-2 | ||||||||||||||||||
154 | /* If fd has just been added, remove it from the list */ | - | ||||||||||||||||||
155 | if (curr->add == 1) {
| 1 | ||||||||||||||||||
156 | if (ctx->fds == curr) {
| 0-1 | ||||||||||||||||||
157 | ctx->fds = curr->next; | - | ||||||||||||||||||
158 | } else { executed 1 time by 1 test: end of block Executed by:
| 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:
| 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:
| 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 | - | |||||||||||||||||||
185 | void 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) {
| 2-9 | ||||||||||||||||||
195 | if (curr->del) {
| 1 | ||||||||||||||||||
196 | if (prev == NULL)
| 0-1 | ||||||||||||||||||
197 | ctx->fds = curr->next; executed 1 time by 1 test: ctx->fds = curr->next; Executed by:
| 1 | ||||||||||||||||||
198 | else | - | ||||||||||||||||||
199 | prev->next = curr->next; never executed: prev->next = curr->next; | 0 | ||||||||||||||||||
200 | OPENSSL_free(curr); | - | ||||||||||||||||||
201 | if (prev == NULL)
| 0-1 | ||||||||||||||||||
202 | curr = ctx->fds; executed 1 time by 1 test: curr = ctx->fds; Executed by:
| 1 | ||||||||||||||||||
203 | else | - | ||||||||||||||||||
204 | curr = prev->next; never executed: curr = prev->next; | 0 | ||||||||||||||||||
205 | continue; executed 1 time by 1 test: continue; Executed by:
| 1 | ||||||||||||||||||
206 | } | - | ||||||||||||||||||
207 | if (curr->add) {
| 0-1 | ||||||||||||||||||
208 | curr->add = 0; | - | ||||||||||||||||||
209 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
210 | prev = curr; | - | ||||||||||||||||||
211 | curr = curr->next; | - | ||||||||||||||||||
212 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
213 | } executed 9 times by 1 test: end of block Executed by:
| 9 | ||||||||||||||||||
Source code | Switch to Preprocessed file |