Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bio/bss_acpt.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 <errno.h> | - | ||||||||||||
12 | #include "bio_lcl.h" | - | ||||||||||||
13 | - | |||||||||||||
14 | #ifndef OPENSSL_NO_SOCK | - | ||||||||||||
15 | - | |||||||||||||
16 | typedef struct bio_accept_st { | - | ||||||||||||
17 | int state; | - | ||||||||||||
18 | int accept_family; | - | ||||||||||||
19 | int bind_mode; /* Socket mode for BIO_listen */ | - | ||||||||||||
20 | int accepted_mode; /* Socket mode for BIO_accept (set on accepted sock) */ | - | ||||||||||||
21 | char *param_addr; | - | ||||||||||||
22 | char *param_serv; | - | ||||||||||||
23 | - | |||||||||||||
24 | int accept_sock; | - | ||||||||||||
25 | - | |||||||||||||
26 | BIO_ADDRINFO *addr_first; | - | ||||||||||||
27 | const BIO_ADDRINFO *addr_iter; | - | ||||||||||||
28 | BIO_ADDR cache_accepting_addr; /* Useful if we asked for port 0 */ | - | ||||||||||||
29 | char *cache_accepting_name, *cache_accepting_serv; | - | ||||||||||||
30 | BIO_ADDR cache_peer_addr; | - | ||||||||||||
31 | char *cache_peer_name, *cache_peer_serv; | - | ||||||||||||
32 | - | |||||||||||||
33 | BIO *bio_chain; | - | ||||||||||||
34 | } BIO_ACCEPT; | - | ||||||||||||
35 | - | |||||||||||||
36 | static int acpt_write(BIO *h, const char *buf, int num); | - | ||||||||||||
37 | static int acpt_read(BIO *h, char *buf, int size); | - | ||||||||||||
38 | static int acpt_puts(BIO *h, const char *str); | - | ||||||||||||
39 | static long acpt_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||
40 | static int acpt_new(BIO *h); | - | ||||||||||||
41 | static int acpt_free(BIO *data); | - | ||||||||||||
42 | static int acpt_state(BIO *b, BIO_ACCEPT *c); | - | ||||||||||||
43 | static void acpt_close_socket(BIO *data); | - | ||||||||||||
44 | static BIO_ACCEPT *BIO_ACCEPT_new(void); | - | ||||||||||||
45 | static void BIO_ACCEPT_free(BIO_ACCEPT *a); | - | ||||||||||||
46 | - | |||||||||||||
47 | # define ACPT_S_BEFORE 1 | - | ||||||||||||
48 | # define ACPT_S_GET_ADDR 2 | - | ||||||||||||
49 | # define ACPT_S_CREATE_SOCKET 3 | - | ||||||||||||
50 | # define ACPT_S_LISTEN 4 | - | ||||||||||||
51 | # define ACPT_S_ACCEPT 5 | - | ||||||||||||
52 | # define ACPT_S_OK 6 | - | ||||||||||||
53 | - | |||||||||||||
54 | static const BIO_METHOD methods_acceptp = { | - | ||||||||||||
55 | BIO_TYPE_ACCEPT, | - | ||||||||||||
56 | "socket accept", | - | ||||||||||||
57 | /* TODO: Convert to new style write function */ | - | ||||||||||||
58 | bwrite_conv, | - | ||||||||||||
59 | acpt_write, | - | ||||||||||||
60 | /* TODO: Convert to new style read function */ | - | ||||||||||||
61 | bread_conv, | - | ||||||||||||
62 | acpt_read, | - | ||||||||||||
63 | acpt_puts, | - | ||||||||||||
64 | NULL, /* connect_gets, */ | - | ||||||||||||
65 | acpt_ctrl, | - | ||||||||||||
66 | acpt_new, | - | ||||||||||||
67 | acpt_free, | - | ||||||||||||
68 | NULL, /* connect_callback_ctrl */ | - | ||||||||||||
69 | }; | - | ||||||||||||
70 | - | |||||||||||||
71 | const BIO_METHOD *BIO_s_accept(void) | - | ||||||||||||
72 | { | - | ||||||||||||
73 | return &methods_acceptp; executed 2 times by 1 test: return &methods_acceptp; Executed by:
| 2 | ||||||||||||
74 | } | - | ||||||||||||
75 | - | |||||||||||||
76 | static int acpt_new(BIO *bi) | - | ||||||||||||
77 | { | - | ||||||||||||
78 | BIO_ACCEPT *ba; | - | ||||||||||||
79 | - | |||||||||||||
80 | bi->init = 0; | - | ||||||||||||
81 | bi->num = (int)INVALID_SOCKET; | - | ||||||||||||
82 | bi->flags = 0; | - | ||||||||||||
83 | if ((ba = BIO_ACCEPT_new()) == NULL)
| 0-2 | ||||||||||||
84 | return 0; never executed: return 0; | 0 | ||||||||||||
85 | bi->ptr = (char *)ba; | - | ||||||||||||
86 | ba->state = ACPT_S_BEFORE; | - | ||||||||||||
87 | bi->shutdown = 1; | - | ||||||||||||
88 | return 1; executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | static BIO_ACCEPT *BIO_ACCEPT_new(void) | - | ||||||||||||
92 | { | - | ||||||||||||
93 | BIO_ACCEPT *ret; | - | ||||||||||||
94 | - | |||||||||||||
95 | if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
| 0-2 | ||||||||||||
96 | BIOerr(BIO_F_BIO_ACCEPT_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
97 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
98 | } | - | ||||||||||||
99 | ret->accept_family = BIO_FAMILY_IPANY; | - | ||||||||||||
100 | ret->accept_sock = (int)INVALID_SOCKET; | - | ||||||||||||
101 | return ret; executed 2 times by 1 test: return ret; Executed by:
| 2 | ||||||||||||
102 | } | - | ||||||||||||
103 | - | |||||||||||||
104 | static void BIO_ACCEPT_free(BIO_ACCEPT *a) | - | ||||||||||||
105 | { | - | ||||||||||||
106 | if (a == NULL)
| 0-2 | ||||||||||||
107 | return; never executed: return; | 0 | ||||||||||||
108 | OPENSSL_free(a->param_addr); | - | ||||||||||||
109 | OPENSSL_free(a->param_serv); | - | ||||||||||||
110 | BIO_ADDRINFO_free(a->addr_first); | - | ||||||||||||
111 | OPENSSL_free(a->cache_accepting_name); | - | ||||||||||||
112 | OPENSSL_free(a->cache_accepting_serv); | - | ||||||||||||
113 | OPENSSL_free(a->cache_peer_name); | - | ||||||||||||
114 | OPENSSL_free(a->cache_peer_serv); | - | ||||||||||||
115 | BIO_free(a->bio_chain); | - | ||||||||||||
116 | OPENSSL_free(a); | - | ||||||||||||
117 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
118 | - | |||||||||||||
119 | static void acpt_close_socket(BIO *bio) | - | ||||||||||||
120 | { | - | ||||||||||||
121 | BIO_ACCEPT *c; | - | ||||||||||||
122 | - | |||||||||||||
123 | c = (BIO_ACCEPT *)bio->ptr; | - | ||||||||||||
124 | if (c->accept_sock != (int)INVALID_SOCKET) {
| 0-2 | ||||||||||||
125 | shutdown(c->accept_sock, 2); | - | ||||||||||||
126 | closesocket(c->accept_sock); | - | ||||||||||||
127 | c->accept_sock = (int)INVALID_SOCKET; | - | ||||||||||||
128 | bio->num = (int)INVALID_SOCKET; | - | ||||||||||||
129 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
130 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
131 | - | |||||||||||||
132 | static int acpt_free(BIO *a) | - | ||||||||||||
133 | { | - | ||||||||||||
134 | BIO_ACCEPT *data; | - | ||||||||||||
135 | - | |||||||||||||
136 | if (a == NULL)
| 0-2 | ||||||||||||
137 | return 0; never executed: return 0; | 0 | ||||||||||||
138 | data = (BIO_ACCEPT *)a->ptr; | - | ||||||||||||
139 | - | |||||||||||||
140 | if (a->shutdown) {
| 0-2 | ||||||||||||
141 | acpt_close_socket(a); | - | ||||||||||||
142 | BIO_ACCEPT_free(data); | - | ||||||||||||
143 | a->ptr = NULL; | - | ||||||||||||
144 | a->flags = 0; | - | ||||||||||||
145 | a->init = 0; | - | ||||||||||||
146 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
147 | return 1; executed 2 times by 1 test: return 1; Executed by:
| 2 | ||||||||||||
148 | } | - | ||||||||||||
149 | - | |||||||||||||
150 | static int acpt_state(BIO *b, BIO_ACCEPT *c) | - | ||||||||||||
151 | { | - | ||||||||||||
152 | BIO *bio = NULL, *dbio; | - | ||||||||||||
153 | int s = -1, ret = -1; | - | ||||||||||||
154 | - | |||||||||||||
155 | for (;;) { | - | ||||||||||||
156 | switch (c->state) { | - | ||||||||||||
157 | case ACPT_S_BEFORE: executed 2 times by 1 test: case 1: Executed by:
| 2 | ||||||||||||
158 | if (c->param_addr == NULL && c->param_serv == NULL) {
| 0-2 | ||||||||||||
159 | BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_ADDR_OR_SERVICE_SPECIFIED); | - | ||||||||||||
160 | ERR_add_error_data(4, | - | ||||||||||||
161 | "hostname=", c->param_addr, | - | ||||||||||||
162 | " service=", c->param_serv); | - | ||||||||||||
163 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
164 | } | - | ||||||||||||
165 | - | |||||||||||||
166 | /* Because we're starting a new bind, any cached name and serv | - | ||||||||||||
167 | * are now obsolete and need to be cleaned out. | - | ||||||||||||
168 | * QUESTION: should this be done in acpt_close_socket() instead? | - | ||||||||||||
169 | */ | - | ||||||||||||
170 | OPENSSL_free(c->cache_accepting_name); | - | ||||||||||||
171 | c->cache_accepting_name = NULL; | - | ||||||||||||
172 | OPENSSL_free(c->cache_accepting_serv); | - | ||||||||||||
173 | c->cache_accepting_serv = NULL; | - | ||||||||||||
174 | OPENSSL_free(c->cache_peer_name); | - | ||||||||||||
175 | c->cache_peer_name = NULL; | - | ||||||||||||
176 | OPENSSL_free(c->cache_peer_serv); | - | ||||||||||||
177 | c->cache_peer_serv = NULL; | - | ||||||||||||
178 | - | |||||||||||||
179 | c->state = ACPT_S_GET_ADDR; | - | ||||||||||||
180 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
181 | - | |||||||||||||
182 | case ACPT_S_GET_ADDR: executed 2 times by 1 test: case 2: Executed by:
| 2 | ||||||||||||
183 | { | - | ||||||||||||
184 | int family = AF_UNSPEC; | - | ||||||||||||
185 | switch (c->accept_family) { | - | ||||||||||||
186 | case BIO_FAMILY_IPV6: executed 1 time by 1 test: case 6: Executed by:
| 1 | ||||||||||||
187 | if (1) { /* This is a trick we use to avoid bit rot. | - | ||||||||||||
188 | * at least the "else" part will always be | - | ||||||||||||
189 | * compiled. | - | ||||||||||||
190 | */ | - | ||||||||||||
191 | #ifdef AF_INET6 | - | ||||||||||||
192 | family = AF_INET6; | - | ||||||||||||
193 | } else { executed 1 time by 1 test: end of block Executed by:
dead code: { ERR_put_error(32,(100),(145),__FILE__,195); goto exit_loop; } | - | ||||||||||||
194 | #endif dead code: { ERR_put_error(32,(100),(145),__FILE__,195); goto exit_loop; } | - | ||||||||||||
195 | BIOerr(BIO_F_ACPT_STATE, BIO_R_UNAVAILABLE_IP_FAMILY); dead code: { ERR_put_error(32,(100),(145),__FILE__,195); goto exit_loop; } | - | ||||||||||||
196 | goto exit_loop; dead code: { ERR_put_error(32,(100),(145),__FILE__,195); goto exit_loop; } | - | ||||||||||||
197 | } dead code: { ERR_put_error(32,(100),(145),__FILE__,195); goto exit_loop; } | - | ||||||||||||
198 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||
199 | case BIO_FAMILY_IPV4: executed 1 time by 1 test: case 4: Executed by:
| 1 | ||||||||||||
200 | family = AF_INET; | - | ||||||||||||
201 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||
202 | case BIO_FAMILY_IPANY: never executed: case 256: | 0 | ||||||||||||
203 | family = AF_UNSPEC; | - | ||||||||||||
204 | break; never executed: break; | 0 | ||||||||||||
205 | default: never executed: default: | 0 | ||||||||||||
206 | BIOerr(BIO_F_ACPT_STATE, BIO_R_UNSUPPORTED_IP_FAMILY); | - | ||||||||||||
207 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
208 | } | - | ||||||||||||
209 | if (BIO_lookup(c->param_addr, c->param_serv, BIO_LOOKUP_SERVER,
| 0-2 | ||||||||||||
210 | family, SOCK_STREAM, &c->addr_first) == 0)
| 0-2 | ||||||||||||
211 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
212 | } | - | ||||||||||||
213 | if (c->addr_first == NULL) {
| 0-2 | ||||||||||||
214 | BIOerr(BIO_F_ACPT_STATE, BIO_R_LOOKUP_RETURNED_NOTHING); | - | ||||||||||||
215 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
216 | } | - | ||||||||||||
217 | /* We're currently not iterating, but set this as preparation | - | ||||||||||||
218 | * for possible future development in that regard | - | ||||||||||||
219 | */ | - | ||||||||||||
220 | c->addr_iter = c->addr_first; | - | ||||||||||||
221 | c->state = ACPT_S_CREATE_SOCKET; | - | ||||||||||||
222 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
223 | - | |||||||||||||
224 | case ACPT_S_CREATE_SOCKET: executed 2 times by 1 test: case 3: Executed by:
| 2 | ||||||||||||
225 | ret = BIO_socket(BIO_ADDRINFO_family(c->addr_iter), | - | ||||||||||||
226 | BIO_ADDRINFO_socktype(c->addr_iter), | - | ||||||||||||
227 | BIO_ADDRINFO_protocol(c->addr_iter), 0); | - | ||||||||||||
228 | if (ret == (int)INVALID_SOCKET) {
| 0-2 | ||||||||||||
229 | SYSerr(SYS_F_SOCKET, get_last_socket_error()); | - | ||||||||||||
230 | ERR_add_error_data(4, | - | ||||||||||||
231 | "hostname=", c->param_addr, | - | ||||||||||||
232 | " service=", c->param_serv); | - | ||||||||||||
233 | BIOerr(BIO_F_ACPT_STATE, BIO_R_UNABLE_TO_CREATE_SOCKET); | - | ||||||||||||
234 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
235 | } | - | ||||||||||||
236 | c->accept_sock = ret; | - | ||||||||||||
237 | b->num = ret; | - | ||||||||||||
238 | c->state = ACPT_S_LISTEN; | - | ||||||||||||
239 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
240 | - | |||||||||||||
241 | case ACPT_S_LISTEN: executed 2 times by 1 test: case 4: Executed by:
| 2 | ||||||||||||
242 | { | - | ||||||||||||
243 | if (!BIO_listen(c->accept_sock,
| 0-2 | ||||||||||||
244 | BIO_ADDRINFO_address(c->addr_iter),
| 0-2 | ||||||||||||
245 | c->bind_mode)) {
| 0-2 | ||||||||||||
246 | BIO_closesocket(c->accept_sock); | - | ||||||||||||
247 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
248 | } | - | ||||||||||||
249 | } | - | ||||||||||||
250 | - | |||||||||||||
251 | { | - | ||||||||||||
252 | union BIO_sock_info_u info; | - | ||||||||||||
253 | - | |||||||||||||
254 | info.addr = &c->cache_accepting_addr; | - | ||||||||||||
255 | if (!BIO_sock_info(c->accept_sock, BIO_SOCK_INFO_ADDRESS,
| 0-2 | ||||||||||||
256 | &info)) {
| 0-2 | ||||||||||||
257 | BIO_closesocket(c->accept_sock); | - | ||||||||||||
258 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
259 | } | - | ||||||||||||
260 | } | - | ||||||||||||
261 | - | |||||||||||||
262 | c->cache_accepting_name = | - | ||||||||||||
263 | BIO_ADDR_hostname_string(&c->cache_accepting_addr, 1); | - | ||||||||||||
264 | c->cache_accepting_serv = | - | ||||||||||||
265 | BIO_ADDR_service_string(&c->cache_accepting_addr, 1); | - | ||||||||||||
266 | c->state = ACPT_S_ACCEPT; | - | ||||||||||||
267 | s = -1; | - | ||||||||||||
268 | ret = 1; | - | ||||||||||||
269 | goto end; executed 2 times by 1 test: goto end; Executed by:
| 2 | ||||||||||||
270 | - | |||||||||||||
271 | case ACPT_S_ACCEPT: executed 2 times by 1 test: case 5: Executed by:
| 2 | ||||||||||||
272 | if (b->next_bio != NULL) {
| 0-2 | ||||||||||||
273 | c->state = ACPT_S_OK; | - | ||||||||||||
274 | break; never executed: break; | 0 | ||||||||||||
275 | } | - | ||||||||||||
276 | BIO_clear_retry_flags(b); | - | ||||||||||||
277 | b->retry_reason = 0; | - | ||||||||||||
278 | - | |||||||||||||
279 | OPENSSL_free(c->cache_peer_name); | - | ||||||||||||
280 | c->cache_peer_name = NULL; | - | ||||||||||||
281 | OPENSSL_free(c->cache_peer_serv); | - | ||||||||||||
282 | c->cache_peer_serv = NULL; | - | ||||||||||||
283 | - | |||||||||||||
284 | s = BIO_accept_ex(c->accept_sock, &c->cache_peer_addr, | - | ||||||||||||
285 | c->accepted_mode); | - | ||||||||||||
286 | - | |||||||||||||
287 | /* If the returned socket is invalid, this might still be | - | ||||||||||||
288 | * retryable | - | ||||||||||||
289 | */ | - | ||||||||||||
290 | if (s < 0) {
| 0-2 | ||||||||||||
291 | if (BIO_sock_should_retry(s)) {
| 0 | ||||||||||||
292 | BIO_set_retry_special(b); | - | ||||||||||||
293 | b->retry_reason = BIO_RR_ACCEPT; | - | ||||||||||||
294 | goto end; never executed: goto end; | 0 | ||||||||||||
295 | } | - | ||||||||||||
296 | } never executed: end of block | 0 | ||||||||||||
297 | - | |||||||||||||
298 | /* If it wasn't retryable, we fail */ | - | ||||||||||||
299 | if (s < 0) {
| 0-2 | ||||||||||||
300 | ret = s; | - | ||||||||||||
301 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
302 | } | - | ||||||||||||
303 | - | |||||||||||||
304 | bio = BIO_new_socket(s, BIO_CLOSE); | - | ||||||||||||
305 | if (bio == NULL)
| 0-2 | ||||||||||||
306 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
307 | - | |||||||||||||
308 | BIO_set_callback(bio, BIO_get_callback(b)); | - | ||||||||||||
309 | BIO_set_callback_arg(bio, BIO_get_callback_arg(b)); | - | ||||||||||||
310 | - | |||||||||||||
311 | /* | - | ||||||||||||
312 | * If the accept BIO has an bio_chain, we dup it and put the new | - | ||||||||||||
313 | * socket at the end. | - | ||||||||||||
314 | */ | - | ||||||||||||
315 | if (c->bio_chain != NULL) {
| 0-2 | ||||||||||||
316 | if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL)
| 0 | ||||||||||||
317 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
318 | if (!BIO_push(dbio, bio))
| 0 | ||||||||||||
319 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
320 | bio = dbio; | - | ||||||||||||
321 | } never executed: end of block | 0 | ||||||||||||
322 | if (BIO_push(b, bio) == NULL)
| 0-2 | ||||||||||||
323 | goto exit_loop; never executed: goto exit_loop; | 0 | ||||||||||||
324 | - | |||||||||||||
325 | c->cache_peer_name = | - | ||||||||||||
326 | BIO_ADDR_hostname_string(&c->cache_peer_addr, 1); | - | ||||||||||||
327 | c->cache_peer_serv = | - | ||||||||||||
328 | BIO_ADDR_service_string(&c->cache_peer_addr, 1); | - | ||||||||||||
329 | c->state = ACPT_S_OK; | - | ||||||||||||
330 | bio = NULL; | - | ||||||||||||
331 | ret = 1; | - | ||||||||||||
332 | goto end; executed 2 times by 1 test: goto end; Executed by:
| 2 | ||||||||||||
333 | - | |||||||||||||
334 | case ACPT_S_OK: never executed: case 6: | 0 | ||||||||||||
335 | if (b->next_bio == NULL) {
| 0 | ||||||||||||
336 | c->state = ACPT_S_ACCEPT; | - | ||||||||||||
337 | break; never executed: break; | 0 | ||||||||||||
338 | } | - | ||||||||||||
339 | ret = 1; | - | ||||||||||||
340 | goto end; never executed: goto end; | 0 | ||||||||||||
341 | - | |||||||||||||
342 | default: never executed: default: | 0 | ||||||||||||
343 | ret = 0; | - | ||||||||||||
344 | goto end; never executed: goto end; | 0 | ||||||||||||
345 | } | - | ||||||||||||
346 | } | - | ||||||||||||
347 | - | |||||||||||||
348 | exit_loop: code before this statement never executed: exit_loop: | 0 | ||||||||||||
349 | if (bio != NULL)
| 0 | ||||||||||||
350 | BIO_free(bio); never executed: BIO_free(bio); | 0 | ||||||||||||
351 | else if (s >= 0)
| 0 | ||||||||||||
352 | BIO_closesocket(s); never executed: BIO_closesocket(s); | 0 | ||||||||||||
353 | end: code before this statement never executed: end: | 0 | ||||||||||||
354 | return ret; executed 4 times by 1 test: return ret; Executed by:
| 4 | ||||||||||||
355 | } | - | ||||||||||||
356 | - | |||||||||||||
357 | static int acpt_read(BIO *b, char *out, int outl) | - | ||||||||||||
358 | { | - | ||||||||||||
359 | int ret = 0; | - | ||||||||||||
360 | BIO_ACCEPT *data; | - | ||||||||||||
361 | - | |||||||||||||
362 | BIO_clear_retry_flags(b); | - | ||||||||||||
363 | data = (BIO_ACCEPT *)b->ptr; | - | ||||||||||||
364 | - | |||||||||||||
365 | while (b->next_bio == NULL) {
| 0 | ||||||||||||
366 | ret = acpt_state(b, data); | - | ||||||||||||
367 | if (ret <= 0)
| 0 | ||||||||||||
368 | return ret; never executed: return ret; | 0 | ||||||||||||
369 | } never executed: end of block | 0 | ||||||||||||
370 | - | |||||||||||||
371 | ret = BIO_read(b->next_bio, out, outl); | - | ||||||||||||
372 | BIO_copy_next_retry(b); | - | ||||||||||||
373 | return ret; never executed: return ret; | 0 | ||||||||||||
374 | } | - | ||||||||||||
375 | - | |||||||||||||
376 | static int acpt_write(BIO *b, const char *in, int inl) | - | ||||||||||||
377 | { | - | ||||||||||||
378 | int ret; | - | ||||||||||||
379 | BIO_ACCEPT *data; | - | ||||||||||||
380 | - | |||||||||||||
381 | BIO_clear_retry_flags(b); | - | ||||||||||||
382 | data = (BIO_ACCEPT *)b->ptr; | - | ||||||||||||
383 | - | |||||||||||||
384 | while (b->next_bio == NULL) {
| 0 | ||||||||||||
385 | ret = acpt_state(b, data); | - | ||||||||||||
386 | if (ret <= 0)
| 0 | ||||||||||||
387 | return ret; never executed: return ret; | 0 | ||||||||||||
388 | } never executed: end of block | 0 | ||||||||||||
389 | - | |||||||||||||
390 | ret = BIO_write(b->next_bio, in, inl); | - | ||||||||||||
391 | BIO_copy_next_retry(b); | - | ||||||||||||
392 | return ret; never executed: return ret; | 0 | ||||||||||||
393 | } | - | ||||||||||||
394 | - | |||||||||||||
395 | static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||
396 | { | - | ||||||||||||
397 | int *ip; | - | ||||||||||||
398 | long ret = 1; | - | ||||||||||||
399 | BIO_ACCEPT *data; | - | ||||||||||||
400 | char **pp; | - | ||||||||||||
401 | - | |||||||||||||
402 | data = (BIO_ACCEPT *)b->ptr; | - | ||||||||||||
403 | - | |||||||||||||
404 | switch (cmd) { | - | ||||||||||||
405 | case BIO_CTRL_RESET: never executed: case 1: | 0 | ||||||||||||
406 | ret = 0; | - | ||||||||||||
407 | data->state = ACPT_S_BEFORE; | - | ||||||||||||
408 | acpt_close_socket(b); | - | ||||||||||||
409 | BIO_ADDRINFO_free(data->addr_first); | - | ||||||||||||
410 | data->addr_first = NULL; | - | ||||||||||||
411 | b->flags = 0; | - | ||||||||||||
412 | break; never executed: break; | 0 | ||||||||||||
413 | case BIO_C_DO_STATE_MACHINE: executed 4 times by 1 test: case 101: Executed by:
| 4 | ||||||||||||
414 | /* use this one to start the connection */ | - | ||||||||||||
415 | ret = (long)acpt_state(b, data); | - | ||||||||||||
416 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||
417 | case BIO_C_SET_ACCEPT: executed 4 times by 1 test: case 118: Executed by:
| 4 | ||||||||||||
418 | if (ptr != NULL) {
| 0-4 | ||||||||||||
419 | if (num == 0) {
| 2 | ||||||||||||
420 | char *hold_serv = data->param_serv; | - | ||||||||||||
421 | /* We affect the hostname regardless. However, the input | - | ||||||||||||
422 | * string might contain a host:service spec, so we must | - | ||||||||||||
423 | * parse it, which might or might not affect the service | - | ||||||||||||
424 | */ | - | ||||||||||||
425 | OPENSSL_free(data->param_addr); | - | ||||||||||||
426 | data->param_addr = NULL; | - | ||||||||||||
427 | ret = BIO_parse_hostserv(ptr, | - | ||||||||||||
428 | &data->param_addr, | - | ||||||||||||
429 | &data->param_serv, | - | ||||||||||||
430 | BIO_PARSE_PRIO_SERV); | - | ||||||||||||
431 | if (hold_serv != data->param_serv)
| 0-2 | ||||||||||||
432 | OPENSSL_free(hold_serv); executed 2 times by 1 test: CRYPTO_free(hold_serv, __FILE__, 432); Executed by:
| 2 | ||||||||||||
433 | b->init = 1; | - | ||||||||||||
434 | } else if (num == 1) { executed 2 times by 1 test: end of block Executed by:
| 0-2 | ||||||||||||
435 | OPENSSL_free(data->param_serv); | - | ||||||||||||
436 | data->param_serv = BUF_strdup(ptr); | - | ||||||||||||
437 | b->init = 1; | - | ||||||||||||
438 | } else if (num == 2) { never executed: end of block
| 0-2 | ||||||||||||
439 | data->bind_mode |= BIO_SOCK_NONBLOCK; | - | ||||||||||||
440 | } else if (num == 3) { never executed: end of block
| 0-2 | ||||||||||||
441 | BIO_free(data->bio_chain); | - | ||||||||||||
442 | data->bio_chain = (BIO *)ptr; | - | ||||||||||||
443 | } else if (num == 4) { never executed: end of block
| 0-2 | ||||||||||||
444 | data->accept_family = *(int *)ptr; | - | ||||||||||||
445 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
446 | } else { executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
447 | if (num == 2) {
| 0 | ||||||||||||
448 | data->bind_mode &= ~BIO_SOCK_NONBLOCK; | - | ||||||||||||
449 | } never executed: end of block | 0 | ||||||||||||
450 | } never executed: end of block | 0 | ||||||||||||
451 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||
452 | case BIO_C_SET_NBIO: executed 2 times by 1 test: case 102: Executed by:
| 2 | ||||||||||||
453 | if (num != 0)
| 0-2 | ||||||||||||
454 | data->accepted_mode |= BIO_SOCK_NONBLOCK; executed 2 times by 1 test: data->accepted_mode |= 0x08; Executed by:
| 2 | ||||||||||||
455 | else | - | ||||||||||||
456 | data->accepted_mode &= ~BIO_SOCK_NONBLOCK; never executed: data->accepted_mode &= ~0x08; | 0 | ||||||||||||
457 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
458 | case BIO_C_SET_FD: never executed: case 104: | 0 | ||||||||||||
459 | b->num = *((int *)ptr); | - | ||||||||||||
460 | data->accept_sock = b->num; | - | ||||||||||||
461 | data->state = ACPT_S_ACCEPT; | - | ||||||||||||
462 | b->shutdown = (int)num; | - | ||||||||||||
463 | b->init = 1; | - | ||||||||||||
464 | break; never executed: break; | 0 | ||||||||||||
465 | case BIO_C_GET_FD: never executed: case 105: | 0 | ||||||||||||
466 | if (b->init) {
| 0 | ||||||||||||
467 | ip = (int *)ptr; | - | ||||||||||||
468 | if (ip != NULL)
| 0 | ||||||||||||
469 | *ip = data->accept_sock; never executed: *ip = data->accept_sock; | 0 | ||||||||||||
470 | ret = data->accept_sock; | - | ||||||||||||
471 | } else never executed: end of block | 0 | ||||||||||||
472 | ret = -1; never executed: ret = -1; | 0 | ||||||||||||
473 | break; never executed: break; | 0 | ||||||||||||
474 | case BIO_C_GET_ACCEPT: executed 2 times by 1 test: case 124: Executed by:
| 2 | ||||||||||||
475 | if (b->init) {
| 0-2 | ||||||||||||
476 | if (num == 0 && ptr != NULL) {
| 0-2 | ||||||||||||
477 | pp = (char **)ptr; | - | ||||||||||||
478 | *pp = data->cache_accepting_name; | - | ||||||||||||
479 | } else if (num == 1 && ptr != NULL) { never executed: end of block
| 0-2 | ||||||||||||
480 | pp = (char **)ptr; | - | ||||||||||||
481 | *pp = data->cache_accepting_serv; | - | ||||||||||||
482 | } else if (num == 2 && ptr != NULL) { executed 2 times by 1 test: end of block Executed by:
| 0-2 | ||||||||||||
483 | pp = (char **)ptr; | - | ||||||||||||
484 | *pp = data->cache_peer_name; | - | ||||||||||||
485 | } else if (num == 3 && ptr != NULL) { never executed: end of block
| 0 | ||||||||||||
486 | pp = (char **)ptr; | - | ||||||||||||
487 | *pp = data->cache_peer_serv; | - | ||||||||||||
488 | } else if (num == 4) { never executed: end of block
| 0 | ||||||||||||
489 | switch (BIO_ADDRINFO_family(data->addr_iter)) { | - | ||||||||||||
490 | #ifdef AF_INET6 | - | ||||||||||||
491 | case AF_INET6: never executed: case 10 : | 0 | ||||||||||||
492 | ret = BIO_FAMILY_IPV6; | - | ||||||||||||
493 | break; never executed: break; | 0 | ||||||||||||
494 | #endif | - | ||||||||||||
495 | case AF_INET: never executed: case 2 : | 0 | ||||||||||||
496 | ret = BIO_FAMILY_IPV4; | - | ||||||||||||
497 | break; never executed: break; | 0 | ||||||||||||
498 | case 0: never executed: case 0: | 0 | ||||||||||||
499 | ret = data->accept_family; | - | ||||||||||||
500 | break; never executed: break; | 0 | ||||||||||||
501 | default: never executed: default: | 0 | ||||||||||||
502 | ret = -1; | - | ||||||||||||
503 | break; never executed: break; | 0 | ||||||||||||
504 | } | - | ||||||||||||
505 | } else | - | ||||||||||||
506 | ret = -1; never executed: ret = -1; | 0 | ||||||||||||
507 | } else | - | ||||||||||||
508 | ret = -1; never executed: ret = -1; | 0 | ||||||||||||
509 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
510 | case BIO_CTRL_GET_CLOSE: never executed: case 8: | 0 | ||||||||||||
511 | ret = b->shutdown; | - | ||||||||||||
512 | break; never executed: break; | 0 | ||||||||||||
513 | case BIO_CTRL_SET_CLOSE: never executed: case 9: | 0 | ||||||||||||
514 | b->shutdown = (int)num; | - | ||||||||||||
515 | break; never executed: break; | 0 | ||||||||||||
516 | case BIO_CTRL_PENDING: never executed: case 10: | 0 | ||||||||||||
517 | case BIO_CTRL_WPENDING: never executed: case 13: | 0 | ||||||||||||
518 | ret = 0; | - | ||||||||||||
519 | break; never executed: break; | 0 | ||||||||||||
520 | case BIO_CTRL_FLUSH: never executed: case 11: | 0 | ||||||||||||
521 | break; never executed: break; | 0 | ||||||||||||
522 | case BIO_C_SET_BIND_MODE: executed 2 times by 1 test: case 131: Executed by:
| 2 | ||||||||||||
523 | data->bind_mode = (int)num; | - | ||||||||||||
524 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||
525 | case BIO_C_GET_BIND_MODE: never executed: case 132: | 0 | ||||||||||||
526 | ret = (long)data->bind_mode; | - | ||||||||||||
527 | break; never executed: break; | 0 | ||||||||||||
528 | case BIO_CTRL_DUP: never executed: case 12: | 0 | ||||||||||||
529 | break; never executed: break; | 0 | ||||||||||||
530 | - | |||||||||||||
531 | default: executed 4 times by 1 test: default: Executed by:
| 4 | ||||||||||||
532 | ret = 0; | - | ||||||||||||
533 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||
534 | } | - | ||||||||||||
535 | return ret; executed 18 times by 1 test: return ret; Executed by:
| 18 | ||||||||||||
536 | } | - | ||||||||||||
537 | - | |||||||||||||
538 | static int acpt_puts(BIO *bp, const char *str) | - | ||||||||||||
539 | { | - | ||||||||||||
540 | int n, ret; | - | ||||||||||||
541 | - | |||||||||||||
542 | n = strlen(str); | - | ||||||||||||
543 | ret = acpt_write(bp, str, n); | - | ||||||||||||
544 | return ret; never executed: return ret; | 0 | ||||||||||||
545 | } | - | ||||||||||||
546 | - | |||||||||||||
547 | BIO *BIO_new_accept(const char *str) | - | ||||||||||||
548 | { | - | ||||||||||||
549 | BIO *ret; | - | ||||||||||||
550 | - | |||||||||||||
551 | ret = BIO_new(BIO_s_accept()); | - | ||||||||||||
552 | if (ret == NULL)
| 0-2 | ||||||||||||
553 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
554 | if (BIO_set_accept_name(ret, str))
| 0-2 | ||||||||||||
555 | return ret; executed 2 times by 1 test: return ret; Executed by:
| 2 | ||||||||||||
556 | BIO_free(ret); | - | ||||||||||||
557 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
558 | } | - | ||||||||||||
559 | - | |||||||||||||
560 | #endif | - | ||||||||||||
Source code | Switch to Preprocessed file |