Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bio/b_addr.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 | #include <assert.h> | - | ||||||||||||||||||||||||||||||
11 | #include <string.h> | - | ||||||||||||||||||||||||||||||
12 | - | |||||||||||||||||||||||||||||||
13 | #include "bio_lcl.h" | - | ||||||||||||||||||||||||||||||
14 | #include <openssl/crypto.h> | - | ||||||||||||||||||||||||||||||
15 | - | |||||||||||||||||||||||||||||||
16 | #ifndef OPENSSL_NO_SOCK | - | ||||||||||||||||||||||||||||||
17 | #include <openssl/err.h> | - | ||||||||||||||||||||||||||||||
18 | #include <openssl/buffer.h> | - | ||||||||||||||||||||||||||||||
19 | #include "internal/thread_once.h" | - | ||||||||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||||||||
21 | CRYPTO_RWLOCK *bio_lookup_lock; | - | ||||||||||||||||||||||||||||||
22 | static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT; | - | ||||||||||||||||||||||||||||||
23 | - | |||||||||||||||||||||||||||||||
24 | /* | - | ||||||||||||||||||||||||||||||
25 | * Throughout this file and bio_lcl.h, the existence of the macro | - | ||||||||||||||||||||||||||||||
26 | * AI_PASSIVE is used to detect the availability of struct addrinfo, | - | ||||||||||||||||||||||||||||||
27 | * getnameinfo() and getaddrinfo(). If that macro doesn't exist, | - | ||||||||||||||||||||||||||||||
28 | * we use our own implementation instead, using gethostbyname, | - | ||||||||||||||||||||||||||||||
29 | * getservbyname and a few other. | - | ||||||||||||||||||||||||||||||
30 | */ | - | ||||||||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||||||||
32 | /********************************************************************** | - | ||||||||||||||||||||||||||||||
33 | * | - | ||||||||||||||||||||||||||||||
34 | * Address structure | - | ||||||||||||||||||||||||||||||
35 | * | - | ||||||||||||||||||||||||||||||
36 | */ | - | ||||||||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||||||||
38 | BIO_ADDR *BIO_ADDR_new(void) | - | ||||||||||||||||||||||||||||||
39 | { | - | ||||||||||||||||||||||||||||||
40 | BIO_ADDR *ret = OPENSSL_zalloc(sizeof(*ret)); | - | ||||||||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||||||||
42 | if (ret == NULL) {
| 0-379 | ||||||||||||||||||||||||||||||
43 | BIOerr(BIO_F_BIO_ADDR_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||
44 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
45 | } | - | ||||||||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||||||||
47 | ret->sa.sa_family = AF_UNSPEC; | - | ||||||||||||||||||||||||||||||
48 | return ret; executed 379 times by 1 test: return ret; Executed by:
| 379 | ||||||||||||||||||||||||||||||
49 | } | - | ||||||||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||||||||
51 | void BIO_ADDR_free(BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
52 | { | - | ||||||||||||||||||||||||||||||
53 | OPENSSL_free(ap); | - | ||||||||||||||||||||||||||||||
54 | } executed 555 times by 1 test: end of block Executed by:
| 555 | ||||||||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||||||||
56 | void BIO_ADDR_clear(BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
57 | { | - | ||||||||||||||||||||||||||||||
58 | memset(ap, 0, sizeof(*ap)); | - | ||||||||||||||||||||||||||||||
59 | ap->sa.sa_family = AF_UNSPEC; | - | ||||||||||||||||||||||||||||||
60 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||||||||
62 | /* | - | ||||||||||||||||||||||||||||||
63 | * BIO_ADDR_make - non-public routine to fill a BIO_ADDR with the contents | - | ||||||||||||||||||||||||||||||
64 | * of a struct sockaddr. | - | ||||||||||||||||||||||||||||||
65 | */ | - | ||||||||||||||||||||||||||||||
66 | int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa) | - | ||||||||||||||||||||||||||||||
67 | { | - | ||||||||||||||||||||||||||||||
68 | if (sa->sa_family == AF_INET) {
| 0 | ||||||||||||||||||||||||||||||
69 | memcpy(&(ap->s_in), sa, sizeof(struct sockaddr_in)); | - | ||||||||||||||||||||||||||||||
70 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
71 | } | - | ||||||||||||||||||||||||||||||
72 | #ifdef AF_INET6 | - | ||||||||||||||||||||||||||||||
73 | if (sa->sa_family == AF_INET6) {
| 0 | ||||||||||||||||||||||||||||||
74 | memcpy(&(ap->s_in6), sa, sizeof(struct sockaddr_in6)); | - | ||||||||||||||||||||||||||||||
75 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
76 | } | - | ||||||||||||||||||||||||||||||
77 | #endif | - | ||||||||||||||||||||||||||||||
78 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
79 | if (sa->sa_family == AF_UNIX) {
| 0 | ||||||||||||||||||||||||||||||
80 | memcpy(&(ap->s_un), sa, sizeof(struct sockaddr_un)); | - | ||||||||||||||||||||||||||||||
81 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
82 | } | - | ||||||||||||||||||||||||||||||
83 | #endif | - | ||||||||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||||||||
85 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
86 | } | - | ||||||||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||||||||
88 | int BIO_ADDR_rawmake(BIO_ADDR *ap, int family, | - | ||||||||||||||||||||||||||||||
89 | const void *where, size_t wherelen, | - | ||||||||||||||||||||||||||||||
90 | unsigned short port) | - | ||||||||||||||||||||||||||||||
91 | { | - | ||||||||||||||||||||||||||||||
92 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
93 | if (family == AF_UNIX) {
| 0 | ||||||||||||||||||||||||||||||
94 | if (wherelen + 1 > sizeof(ap->s_un.sun_path))
| 0 | ||||||||||||||||||||||||||||||
95 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
96 | memset(&ap->s_un, 0, sizeof(ap->s_un)); | - | ||||||||||||||||||||||||||||||
97 | ap->s_un.sun_family = family; | - | ||||||||||||||||||||||||||||||
98 | strncpy(ap->s_un.sun_path, where, sizeof(ap->s_un.sun_path) - 1); | - | ||||||||||||||||||||||||||||||
99 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
100 | } | - | ||||||||||||||||||||||||||||||
101 | #endif | - | ||||||||||||||||||||||||||||||
102 | if (family == AF_INET) {
| 0 | ||||||||||||||||||||||||||||||
103 | if (wherelen != sizeof(struct in_addr))
| 0 | ||||||||||||||||||||||||||||||
104 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
105 | memset(&ap->s_in, 0, sizeof(ap->s_in)); | - | ||||||||||||||||||||||||||||||
106 | ap->s_in.sin_family = family; | - | ||||||||||||||||||||||||||||||
107 | ap->s_in.sin_port = port; | - | ||||||||||||||||||||||||||||||
108 | ap->s_in.sin_addr = *(struct in_addr *)where; | - | ||||||||||||||||||||||||||||||
109 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
110 | } | - | ||||||||||||||||||||||||||||||
111 | #ifdef AF_INET6 | - | ||||||||||||||||||||||||||||||
112 | if (family == AF_INET6) {
| 0 | ||||||||||||||||||||||||||||||
113 | if (wherelen != sizeof(struct in6_addr))
| 0 | ||||||||||||||||||||||||||||||
114 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
115 | memset(&ap->s_in6, 0, sizeof(ap->s_in6)); | - | ||||||||||||||||||||||||||||||
116 | ap->s_in6.sin6_family = family; | - | ||||||||||||||||||||||||||||||
117 | ap->s_in6.sin6_port = port; | - | ||||||||||||||||||||||||||||||
118 | ap->s_in6.sin6_addr = *(struct in6_addr *)where; | - | ||||||||||||||||||||||||||||||
119 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
120 | } | - | ||||||||||||||||||||||||||||||
121 | #endif | - | ||||||||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||||||||
123 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
124 | } | - | ||||||||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||||||||
126 | int BIO_ADDR_family(const BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
127 | { | - | ||||||||||||||||||||||||||||||
128 | return ap->sa.sa_family; executed 178 times by 1 test: return ap->sa.sa_family; Executed by:
| 178 | ||||||||||||||||||||||||||||||
129 | } | - | ||||||||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||||||||
131 | int BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l) | - | ||||||||||||||||||||||||||||||
132 | { | - | ||||||||||||||||||||||||||||||
133 | size_t len = 0; | - | ||||||||||||||||||||||||||||||
134 | const void *addrptr = NULL; | - | ||||||||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||||||||
136 | if (ap->sa.sa_family == AF_INET) {
| 0 | ||||||||||||||||||||||||||||||
137 | len = sizeof(ap->s_in.sin_addr); | - | ||||||||||||||||||||||||||||||
138 | addrptr = &ap->s_in.sin_addr; | - | ||||||||||||||||||||||||||||||
139 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
140 | #ifdef AF_INET6 | - | ||||||||||||||||||||||||||||||
141 | else if (ap->sa.sa_family == AF_INET6) {
| 0 | ||||||||||||||||||||||||||||||
142 | len = sizeof(ap->s_in6.sin6_addr); | - | ||||||||||||||||||||||||||||||
143 | addrptr = &ap->s_in6.sin6_addr; | - | ||||||||||||||||||||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
145 | #endif | - | ||||||||||||||||||||||||||||||
146 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
147 | else if (ap->sa.sa_family == AF_UNIX) {
| 0 | ||||||||||||||||||||||||||||||
148 | len = strlen(ap->s_un.sun_path); | - | ||||||||||||||||||||||||||||||
149 | addrptr = &ap->s_un.sun_path; | - | ||||||||||||||||||||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
151 | #endif | - | ||||||||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||||||||
153 | if (addrptr == NULL)
| 0 | ||||||||||||||||||||||||||||||
154 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||||||||
156 | if (p != NULL) {
| 0 | ||||||||||||||||||||||||||||||
157 | memcpy(p, addrptr, len); | - | ||||||||||||||||||||||||||||||
158 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
159 | if (l != NULL)
| 0 | ||||||||||||||||||||||||||||||
160 | *l = len; never executed: *l = len; | 0 | ||||||||||||||||||||||||||||||
161 | - | |||||||||||||||||||||||||||||||
162 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
163 | } | - | ||||||||||||||||||||||||||||||
164 | - | |||||||||||||||||||||||||||||||
165 | unsigned short BIO_ADDR_rawport(const BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
166 | { | - | ||||||||||||||||||||||||||||||
167 | if (ap->sa.sa_family == AF_INET)
| 0-176 | ||||||||||||||||||||||||||||||
168 | return ap->s_in.sin_port; never executed: return ap->s_in.sin_port; | 0 | ||||||||||||||||||||||||||||||
169 | #ifdef AF_INET6 | - | ||||||||||||||||||||||||||||||
170 | if (ap->sa.sa_family == AF_INET6)
| 0-176 | ||||||||||||||||||||||||||||||
171 | return ap->s_in6.sin6_port; executed 176 times by 1 test: return ap->s_in6.sin6_port; Executed by:
| 176 | ||||||||||||||||||||||||||||||
172 | #endif | - | ||||||||||||||||||||||||||||||
173 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
174 | } | - | ||||||||||||||||||||||||||||||
175 | - | |||||||||||||||||||||||||||||||
176 | /*- | - | ||||||||||||||||||||||||||||||
177 | * addr_strings - helper function to get host and service names | - | ||||||||||||||||||||||||||||||
178 | * @ap: the BIO_ADDR that has the input info | - | ||||||||||||||||||||||||||||||
179 | * @numeric: 0 if actual names should be returned, 1 if the numeric | - | ||||||||||||||||||||||||||||||
180 | * representation should be returned. | - | ||||||||||||||||||||||||||||||
181 | * @hostname: a pointer to a pointer to a memory area to store the | - | ||||||||||||||||||||||||||||||
182 | * host name or numeric representation. Unused if NULL. | - | ||||||||||||||||||||||||||||||
183 | * @service: a pointer to a pointer to a memory area to store the | - | ||||||||||||||||||||||||||||||
184 | * service name or numeric representation. Unused if NULL. | - | ||||||||||||||||||||||||||||||
185 | * | - | ||||||||||||||||||||||||||||||
186 | * The return value is 0 on failure, with the error code in the error | - | ||||||||||||||||||||||||||||||
187 | * stack, and 1 on success. | - | ||||||||||||||||||||||||||||||
188 | */ | - | ||||||||||||||||||||||||||||||
189 | static int addr_strings(const BIO_ADDR *ap, int numeric, | - | ||||||||||||||||||||||||||||||
190 | char **hostname, char **service) | - | ||||||||||||||||||||||||||||||
191 | { | - | ||||||||||||||||||||||||||||||
192 | if (BIO_sock_init() != 1)
| 0-360 | ||||||||||||||||||||||||||||||
193 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||
195 | if (1) { | - | ||||||||||||||||||||||||||||||
196 | #ifdef AI_PASSIVE | - | ||||||||||||||||||||||||||||||
197 | int ret = 0; | - | ||||||||||||||||||||||||||||||
198 | char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = ""; | - | ||||||||||||||||||||||||||||||
199 | int flags = 0; | - | ||||||||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||||||||
201 | if (numeric)
| 0-360 | ||||||||||||||||||||||||||||||
202 | flags |= NI_NUMERICHOST | NI_NUMERICSERV; executed 360 times by 1 test: flags |= 1 | 2 ; Executed by:
| 360 | ||||||||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||||||||
204 | if ((ret = getnameinfo(BIO_ADDR_sockaddr(ap),
| 0-360 | ||||||||||||||||||||||||||||||
205 | BIO_ADDR_sockaddr_size(ap),
| 0-360 | ||||||||||||||||||||||||||||||
206 | host, sizeof(host), serv, sizeof(serv),
| 0-360 | ||||||||||||||||||||||||||||||
207 | flags)) != 0) {
| 0-360 | ||||||||||||||||||||||||||||||
208 | # ifdef EAI_SYSTEM | - | ||||||||||||||||||||||||||||||
209 | if (ret == EAI_SYSTEM) {
| 0 | ||||||||||||||||||||||||||||||
210 | SYSerr(SYS_F_GETNAMEINFO, get_last_socket_error()); | - | ||||||||||||||||||||||||||||||
211 | BIOerr(BIO_F_ADDR_STRINGS, ERR_R_SYS_LIB); | - | ||||||||||||||||||||||||||||||
212 | } else never executed: end of block | 0 | ||||||||||||||||||||||||||||||
213 | # endif | - | ||||||||||||||||||||||||||||||
214 | { | - | ||||||||||||||||||||||||||||||
215 | BIOerr(BIO_F_ADDR_STRINGS, ERR_R_SYS_LIB); | - | ||||||||||||||||||||||||||||||
216 | ERR_add_error_data(1, gai_strerror(ret)); | - | ||||||||||||||||||||||||||||||
217 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
218 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
219 | } | - | ||||||||||||||||||||||||||||||
220 | - | |||||||||||||||||||||||||||||||
221 | /* VMS getnameinfo() has a bug, it doesn't fill in serv, which | - | ||||||||||||||||||||||||||||||
222 | * leaves it with whatever garbage that happens to be there. | - | ||||||||||||||||||||||||||||||
223 | * However, we initialise serv with the empty string (serv[0] | - | ||||||||||||||||||||||||||||||
224 | * is therefore NUL), so it gets real easy to detect when things | - | ||||||||||||||||||||||||||||||
225 | * didn't go the way one might expect. | - | ||||||||||||||||||||||||||||||
226 | */ | - | ||||||||||||||||||||||||||||||
227 | if (serv[0] == '\0') {
| 0-360 | ||||||||||||||||||||||||||||||
228 | BIO_snprintf(serv, sizeof(serv), "%d", | - | ||||||||||||||||||||||||||||||
229 | ntohs(BIO_ADDR_rawport(ap))); never executed: __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); never executed: __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc");
| 0 | ||||||||||||||||||||||||||||||
230 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||||||||
232 | if (hostname != NULL)
| 180 | ||||||||||||||||||||||||||||||
233 | *hostname = OPENSSL_strdup(host); executed 180 times by 1 test: *hostname = CRYPTO_strdup(host, __FILE__, 233); Executed by:
| 180 | ||||||||||||||||||||||||||||||
234 | if (service != NULL)
| 180 | ||||||||||||||||||||||||||||||
235 | *service = OPENSSL_strdup(serv); executed 180 times by 1 test: *service = CRYPTO_strdup(serv, __FILE__, 235); Executed by:
| 180 | ||||||||||||||||||||||||||||||
236 | } else { executed 360 times by 1 test: end of block Executed by:
dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
237 | #endif dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
238 | if (hostname != NULL) dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
239 | *hostname = OPENSSL_strdup(inet_ntoa(ap->s_in.sin_addr)); dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
240 | if (service != NULL) { dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
241 | char serv[6]; /* port is 16 bits => max 5 decimal digits */ dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
242 | BIO_snprintf(serv, sizeof(serv), "%d", ntohs(ap->s_in.sin_port)); dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
243 | *service = OPENSSL_strdup(serv); dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
244 | } dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
245 | } dead code: { if (hostname != ((void *)0) ) *hostname = CRYPTO_strdup(inet_ntoa(ap->s_in.sin_addr), __FILE__, 239); if (service != ((void *)0) ) { char serv[6]; BIO_snprintf(serv, sizeof(serv), "%d", (__extension__ ({ unsigned short int __v, __x = (unsigned short int...p->s_in.sin_port ); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; })) ); *service = CRYPTO_strdup(serv, __FILE__, 243); } } | - | ||||||||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||||||||
247 | if ((hostname != NULL && *hostname == NULL)
| 0-180 | ||||||||||||||||||||||||||||||
248 | || (service != NULL && *service == NULL)) {
| 0-180 | ||||||||||||||||||||||||||||||
249 | if (hostname != NULL) {
| 0 | ||||||||||||||||||||||||||||||
250 | OPENSSL_free(*hostname); | - | ||||||||||||||||||||||||||||||
251 | *hostname = NULL; | - | ||||||||||||||||||||||||||||||
252 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
253 | if (service != NULL) {
| 0 | ||||||||||||||||||||||||||||||
254 | OPENSSL_free(*service); | - | ||||||||||||||||||||||||||||||
255 | *service = NULL; | - | ||||||||||||||||||||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
257 | BIOerr(BIO_F_ADDR_STRINGS, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||
258 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
259 | } | - | ||||||||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||||||||
261 | return 1; executed 360 times by 1 test: return 1; Executed by:
| 360 | ||||||||||||||||||||||||||||||
262 | } | - | ||||||||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||||||||
264 | char *BIO_ADDR_hostname_string(const BIO_ADDR *ap, int numeric) | - | ||||||||||||||||||||||||||||||
265 | { | - | ||||||||||||||||||||||||||||||
266 | char *hostname = NULL; | - | ||||||||||||||||||||||||||||||
267 | - | |||||||||||||||||||||||||||||||
268 | if (addr_strings(ap, numeric, &hostname, NULL))
| 0-180 | ||||||||||||||||||||||||||||||
269 | return hostname; executed 180 times by 1 test: return hostname; Executed by:
| 180 | ||||||||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||||||||
271 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
272 | } | - | ||||||||||||||||||||||||||||||
273 | - | |||||||||||||||||||||||||||||||
274 | char *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric) | - | ||||||||||||||||||||||||||||||
275 | { | - | ||||||||||||||||||||||||||||||
276 | char *service = NULL; | - | ||||||||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||||||||
278 | if (addr_strings(ap, numeric, NULL, &service))
| 0-180 | ||||||||||||||||||||||||||||||
279 | return service; executed 180 times by 1 test: return service; Executed by:
| 180 | ||||||||||||||||||||||||||||||
280 | - | |||||||||||||||||||||||||||||||
281 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
282 | } | - | ||||||||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||||||||
284 | char *BIO_ADDR_path_string(const BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
285 | { | - | ||||||||||||||||||||||||||||||
286 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
287 | if (ap->sa.sa_family == AF_UNIX)
| 0 | ||||||||||||||||||||||||||||||
288 | return OPENSSL_strdup(ap->s_un.sun_path); never executed: return CRYPTO_strdup(ap->s_un.sun_path, __FILE__, 288); | 0 | ||||||||||||||||||||||||||||||
289 | #endif | - | ||||||||||||||||||||||||||||||
290 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
291 | } | - | ||||||||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||||||||
293 | /* | - | ||||||||||||||||||||||||||||||
294 | * BIO_ADDR_sockaddr - non-public routine to return the struct sockaddr | - | ||||||||||||||||||||||||||||||
295 | * for a given BIO_ADDR. In reality, this is simply a type safe cast. | - | ||||||||||||||||||||||||||||||
296 | * The returned struct sockaddr is const, so it can't be tampered with. | - | ||||||||||||||||||||||||||||||
297 | */ | - | ||||||||||||||||||||||||||||||
298 | const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
299 | { | - | ||||||||||||||||||||||||||||||
300 | return &(ap->sa); executed 731 times by 1 test: return &(ap->sa); Executed by:
| 731 | ||||||||||||||||||||||||||||||
301 | } | - | ||||||||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||||||||
303 | /* | - | ||||||||||||||||||||||||||||||
304 | * BIO_ADDR_sockaddr_noconst - non-public function that does the same | - | ||||||||||||||||||||||||||||||
305 | * as BIO_ADDR_sockaddr, but returns a non-const. USE WITH CARE, as | - | ||||||||||||||||||||||||||||||
306 | * it allows you to tamper with the data (and thereby the contents | - | ||||||||||||||||||||||||||||||
307 | * of the input BIO_ADDR). | - | ||||||||||||||||||||||||||||||
308 | */ | - | ||||||||||||||||||||||||||||||
309 | struct sockaddr *BIO_ADDR_sockaddr_noconst(BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
310 | { | - | ||||||||||||||||||||||||||||||
311 | return &(ap->sa); executed 371 times by 1 test: return &(ap->sa); Executed by:
| 371 | ||||||||||||||||||||||||||||||
312 | } | - | ||||||||||||||||||||||||||||||
313 | - | |||||||||||||||||||||||||||||||
314 | /* | - | ||||||||||||||||||||||||||||||
315 | * BIO_ADDR_sockaddr_size - non-public function that returns the size | - | ||||||||||||||||||||||||||||||
316 | * of the struct sockaddr the BIO_ADDR is using. If the protocol family | - | ||||||||||||||||||||||||||||||
317 | * isn't set or is something other than AF_INET, AF_INET6 or AF_UNIX, | - | ||||||||||||||||||||||||||||||
318 | * the size of the BIO_ADDR type is returned. | - | ||||||||||||||||||||||||||||||
319 | */ | - | ||||||||||||||||||||||||||||||
320 | socklen_t BIO_ADDR_sockaddr_size(const BIO_ADDR *ap) | - | ||||||||||||||||||||||||||||||
321 | { | - | ||||||||||||||||||||||||||||||
322 | if (ap->sa.sa_family == AF_INET)
| 6-725 | ||||||||||||||||||||||||||||||
323 | return sizeof(ap->s_in); executed 6 times by 1 test: return sizeof(ap->s_in); Executed by:
| 6 | ||||||||||||||||||||||||||||||
324 | #ifdef AF_INET6 | - | ||||||||||||||||||||||||||||||
325 | if (ap->sa.sa_family == AF_INET6)
| 0-725 | ||||||||||||||||||||||||||||||
326 | return sizeof(ap->s_in6); executed 725 times by 1 test: return sizeof(ap->s_in6); Executed by:
| 725 | ||||||||||||||||||||||||||||||
327 | #endif | - | ||||||||||||||||||||||||||||||
328 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
329 | if (ap->sa.sa_family == AF_UNIX)
| 0 | ||||||||||||||||||||||||||||||
330 | return sizeof(ap->s_un); never executed: return sizeof(ap->s_un); | 0 | ||||||||||||||||||||||||||||||
331 | #endif | - | ||||||||||||||||||||||||||||||
332 | return sizeof(*ap); never executed: return sizeof(*ap); | 0 | ||||||||||||||||||||||||||||||
333 | } | - | ||||||||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||||||||
335 | /********************************************************************** | - | ||||||||||||||||||||||||||||||
336 | * | - | ||||||||||||||||||||||||||||||
337 | * Address info database | - | ||||||||||||||||||||||||||||||
338 | * | - | ||||||||||||||||||||||||||||||
339 | */ | - | ||||||||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||||||||
341 | const BIO_ADDRINFO *BIO_ADDRINFO_next(const BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
342 | { | - | ||||||||||||||||||||||||||||||
343 | if (bai != NULL)
| 0-176 | ||||||||||||||||||||||||||||||
344 | return bai->bai_next; executed 176 times by 1 test: return bai->ai_next; Executed by:
| 176 | ||||||||||||||||||||||||||||||
345 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
346 | } | - | ||||||||||||||||||||||||||||||
347 | - | |||||||||||||||||||||||||||||||
348 | int BIO_ADDRINFO_family(const BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
349 | { | - | ||||||||||||||||||||||||||||||
350 | if (bai != NULL)
| 0-371 | ||||||||||||||||||||||||||||||
351 | return bai->bai_family; executed 371 times by 1 test: return bai->ai_family; Executed by:
| 371 | ||||||||||||||||||||||||||||||
352 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
353 | } | - | ||||||||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||||||||
355 | int BIO_ADDRINFO_socktype(const BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
356 | { | - | ||||||||||||||||||||||||||||||
357 | if (bai != NULL)
| 0-738 | ||||||||||||||||||||||||||||||
358 | return bai->bai_socktype; executed 738 times by 1 test: return bai->ai_socktype; Executed by:
| 738 | ||||||||||||||||||||||||||||||
359 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
360 | } | - | ||||||||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||||||||
362 | int BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
363 | { | - | ||||||||||||||||||||||||||||||
364 | if (bai != NULL) {
| 0-371 | ||||||||||||||||||||||||||||||
365 | if (bai->bai_protocol != 0)
| 0-371 | ||||||||||||||||||||||||||||||
366 | return bai->bai_protocol; executed 371 times by 1 test: return bai->ai_protocol; Executed by:
| 371 | ||||||||||||||||||||||||||||||
367 | - | |||||||||||||||||||||||||||||||
368 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
369 | if (bai->bai_family == AF_UNIX)
| 0 | ||||||||||||||||||||||||||||||
370 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
371 | #endif | - | ||||||||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||||||||
373 | switch (bai->bai_socktype) { | - | ||||||||||||||||||||||||||||||
374 | case SOCK_STREAM: never executed: case SOCK_STREAM : | 0 | ||||||||||||||||||||||||||||||
375 | return IPPROTO_TCP; never executed: return IPPROTO_TCP ; | 0 | ||||||||||||||||||||||||||||||
376 | case SOCK_DGRAM: never executed: case SOCK_DGRAM : | 0 | ||||||||||||||||||||||||||||||
377 | return IPPROTO_UDP; never executed: return IPPROTO_UDP ; | 0 | ||||||||||||||||||||||||||||||
378 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
379 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
380 | } | - | ||||||||||||||||||||||||||||||
381 | } | - | ||||||||||||||||||||||||||||||
382 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
383 | } | - | ||||||||||||||||||||||||||||||
384 | - | |||||||||||||||||||||||||||||||
385 | /* | - | ||||||||||||||||||||||||||||||
386 | * BIO_ADDRINFO_sockaddr_size - non-public function that returns the size | - | ||||||||||||||||||||||||||||||
387 | * of the struct sockaddr inside the BIO_ADDRINFO. | - | ||||||||||||||||||||||||||||||
388 | */ | - | ||||||||||||||||||||||||||||||
389 | socklen_t BIO_ADDRINFO_sockaddr_size(const BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
390 | { | - | ||||||||||||||||||||||||||||||
391 | if (bai != NULL)
| 0 | ||||||||||||||||||||||||||||||
392 | return bai->bai_addrlen; never executed: return bai->ai_addrlen; | 0 | ||||||||||||||||||||||||||||||
393 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
394 | } | - | ||||||||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||||||||
396 | /* | - | ||||||||||||||||||||||||||||||
397 | * BIO_ADDRINFO_sockaddr - non-public function that returns bai_addr | - | ||||||||||||||||||||||||||||||
398 | * as the struct sockaddr it is. | - | ||||||||||||||||||||||||||||||
399 | */ | - | ||||||||||||||||||||||||||||||
400 | const struct sockaddr *BIO_ADDRINFO_sockaddr(const BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
401 | { | - | ||||||||||||||||||||||||||||||
402 | if (bai != NULL)
| 0 | ||||||||||||||||||||||||||||||
403 | return bai->bai_addr; never executed: return bai->ai_addr; | 0 | ||||||||||||||||||||||||||||||
404 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
405 | } | - | ||||||||||||||||||||||||||||||
406 | - | |||||||||||||||||||||||||||||||
407 | const BIO_ADDR *BIO_ADDRINFO_address(const BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
408 | { | - | ||||||||||||||||||||||||||||||
409 | if (bai != NULL)
| 0-371 | ||||||||||||||||||||||||||||||
410 | return (BIO_ADDR *)bai->bai_addr; executed 371 times by 1 test: return (BIO_ADDR *)bai->ai_addr; Executed by:
| 371 | ||||||||||||||||||||||||||||||
411 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
412 | } | - | ||||||||||||||||||||||||||||||
413 | - | |||||||||||||||||||||||||||||||
414 | void BIO_ADDRINFO_free(BIO_ADDRINFO *bai) | - | ||||||||||||||||||||||||||||||
415 | { | - | ||||||||||||||||||||||||||||||
416 | if (bai == NULL)
| 0-371 | ||||||||||||||||||||||||||||||
417 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||||||||
419 | #ifdef AI_PASSIVE | - | ||||||||||||||||||||||||||||||
420 | # ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
421 | # define _cond bai->bai_family != AF_UNIX | - | ||||||||||||||||||||||||||||||
422 | # else | - | ||||||||||||||||||||||||||||||
423 | # define _cond 1 | - | ||||||||||||||||||||||||||||||
424 | # endif | - | ||||||||||||||||||||||||||||||
425 | if (_cond) {
| 0-371 | ||||||||||||||||||||||||||||||
426 | freeaddrinfo(bai); | - | ||||||||||||||||||||||||||||||
427 | return; executed 371 times by 1 test: return; Executed by:
| 371 | ||||||||||||||||||||||||||||||
428 | } | - | ||||||||||||||||||||||||||||||
429 | #endif | - | ||||||||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||||||||
431 | /* Free manually when we know that addrinfo_wrap() was used. | - | ||||||||||||||||||||||||||||||
432 | * See further comment above addrinfo_wrap() | - | ||||||||||||||||||||||||||||||
433 | */ | - | ||||||||||||||||||||||||||||||
434 | while (bai != NULL) {
| 0 | ||||||||||||||||||||||||||||||
435 | BIO_ADDRINFO *next = bai->bai_next; | - | ||||||||||||||||||||||||||||||
436 | OPENSSL_free(bai->bai_addr); | - | ||||||||||||||||||||||||||||||
437 | OPENSSL_free(bai); | - | ||||||||||||||||||||||||||||||
438 | bai = next; | - | ||||||||||||||||||||||||||||||
439 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
440 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
441 | - | |||||||||||||||||||||||||||||||
442 | /********************************************************************** | - | ||||||||||||||||||||||||||||||
443 | * | - | ||||||||||||||||||||||||||||||
444 | * Service functions | - | ||||||||||||||||||||||||||||||
445 | * | - | ||||||||||||||||||||||||||||||
446 | */ | - | ||||||||||||||||||||||||||||||
447 | - | |||||||||||||||||||||||||||||||
448 | /*- | - | ||||||||||||||||||||||||||||||
449 | * The specs in hostserv can take these forms: | - | ||||||||||||||||||||||||||||||
450 | * | - | ||||||||||||||||||||||||||||||
451 | * host:service => *host = "host", *service = "service" | - | ||||||||||||||||||||||||||||||
452 | * host:* => *host = "host", *service = NULL | - | ||||||||||||||||||||||||||||||
453 | * host: => *host = "host", *service = NULL | - | ||||||||||||||||||||||||||||||
454 | * :service => *host = NULL, *service = "service" | - | ||||||||||||||||||||||||||||||
455 | * *:service => *host = NULL, *service = "service" | - | ||||||||||||||||||||||||||||||
456 | * | - | ||||||||||||||||||||||||||||||
457 | * in case no : is present in the string, the result depends on | - | ||||||||||||||||||||||||||||||
458 | * hostserv_prio, as follows: | - | ||||||||||||||||||||||||||||||
459 | * | - | ||||||||||||||||||||||||||||||
460 | * when hostserv_prio == BIO_PARSE_PRIO_HOST | - | ||||||||||||||||||||||||||||||
461 | * host => *host = "host", *service untouched | - | ||||||||||||||||||||||||||||||
462 | * | - | ||||||||||||||||||||||||||||||
463 | * when hostserv_prio == BIO_PARSE_PRIO_SERV | - | ||||||||||||||||||||||||||||||
464 | * service => *host untouched, *service = "service" | - | ||||||||||||||||||||||||||||||
465 | * | - | ||||||||||||||||||||||||||||||
466 | */ | - | ||||||||||||||||||||||||||||||
467 | int BIO_parse_hostserv(const char *hostserv, char **host, char **service, | - | ||||||||||||||||||||||||||||||
468 | enum BIO_hostserv_priorities hostserv_prio) | - | ||||||||||||||||||||||||||||||
469 | { | - | ||||||||||||||||||||||||||||||
470 | const char *h = NULL; size_t hl = 0; | - | ||||||||||||||||||||||||||||||
471 | const char *p = NULL; size_t pl = 0; | - | ||||||||||||||||||||||||||||||
472 | - | |||||||||||||||||||||||||||||||
473 | if (*hostserv == '[') {
| 3-368 | ||||||||||||||||||||||||||||||
474 | if ((p = strchr(hostserv, ']')) == NULL)
| 0-368 | ||||||||||||||||||||||||||||||
475 | goto spec_err; never executed: goto spec_err; | 0 | ||||||||||||||||||||||||||||||
476 | h = hostserv + 1; | - | ||||||||||||||||||||||||||||||
477 | hl = p - h; | - | ||||||||||||||||||||||||||||||
478 | p++; | - | ||||||||||||||||||||||||||||||
479 | if (*p == '\0')
| 0-368 | ||||||||||||||||||||||||||||||
480 | p = NULL; never executed: p = ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
481 | else if (*p != ':')
| 0-368 | ||||||||||||||||||||||||||||||
482 | goto spec_err; never executed: goto spec_err; | 0 | ||||||||||||||||||||||||||||||
483 | else { | - | ||||||||||||||||||||||||||||||
484 | p++; | - | ||||||||||||||||||||||||||||||
485 | pl = strlen(p); | - | ||||||||||||||||||||||||||||||
486 | } executed 368 times by 1 test: end of block Executed by:
| 368 | ||||||||||||||||||||||||||||||
487 | } else { | - | ||||||||||||||||||||||||||||||
488 | const char *p2 = strrchr(hostserv, ':'); | - | ||||||||||||||||||||||||||||||
489 | p = strchr(hostserv, ':');
| 0-3 | ||||||||||||||||||||||||||||||
490 | - | |||||||||||||||||||||||||||||||
491 | /*- | - | ||||||||||||||||||||||||||||||
492 | * Check for more than one colon. There are three possible | - | ||||||||||||||||||||||||||||||
493 | * interpretations: | - | ||||||||||||||||||||||||||||||
494 | * 1. IPv6 address with port number, last colon being separator. | - | ||||||||||||||||||||||||||||||
495 | * 2. IPv6 address only. | - | ||||||||||||||||||||||||||||||
496 | * 3. IPv6 address only if hostserv_prio == BIO_PARSE_PRIO_HOST, | - | ||||||||||||||||||||||||||||||
497 | * IPv6 address and port number if hostserv_prio == BIO_PARSE_PRIO_SERV | - | ||||||||||||||||||||||||||||||
498 | * Because of this ambiguity, we currently choose to make it an | - | ||||||||||||||||||||||||||||||
499 | * error. | - | ||||||||||||||||||||||||||||||
500 | */ | - | ||||||||||||||||||||||||||||||
501 | if (p != p2)
| 0-3 | ||||||||||||||||||||||||||||||
502 | goto amb_err; never executed: goto amb_err; | 0 | ||||||||||||||||||||||||||||||
503 | - | |||||||||||||||||||||||||||||||
504 | if (p != NULL) {
| 0-3 | ||||||||||||||||||||||||||||||
505 | h = hostserv; | - | ||||||||||||||||||||||||||||||
506 | hl = p - h; | - | ||||||||||||||||||||||||||||||
507 | p++; | - | ||||||||||||||||||||||||||||||
508 | pl = strlen(p); | - | ||||||||||||||||||||||||||||||
509 | } else if (hostserv_prio == BIO_PARSE_PRIO_HOST) { executed 3 times by 1 test: end of block Executed by:
| 0-3 | ||||||||||||||||||||||||||||||
510 | h = hostserv; | - | ||||||||||||||||||||||||||||||
511 | hl = strlen(h); | - | ||||||||||||||||||||||||||||||
512 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
513 | p = hostserv; | - | ||||||||||||||||||||||||||||||
514 | pl = strlen(p); | - | ||||||||||||||||||||||||||||||
515 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
516 | } | - | ||||||||||||||||||||||||||||||
517 | - | |||||||||||||||||||||||||||||||
518 | if (p != NULL && strchr(p, ':'))
| 0-371 | ||||||||||||||||||||||||||||||
519 | goto spec_err; never executed: goto spec_err; | 0 | ||||||||||||||||||||||||||||||
520 | - | |||||||||||||||||||||||||||||||
521 | if (h != NULL && host != NULL) {
| 0-371 | ||||||||||||||||||||||||||||||
522 | if (hl == 0
| 2-369 | ||||||||||||||||||||||||||||||
523 | || (hl == 1 && h[0] == '*')) {
| 0-369 | ||||||||||||||||||||||||||||||
524 | *host = NULL; | - | ||||||||||||||||||||||||||||||
525 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||||||||
526 | *host = OPENSSL_strndup(h, hl); | - | ||||||||||||||||||||||||||||||
527 | if (*host == NULL)
| 0-369 | ||||||||||||||||||||||||||||||
528 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||||||||
529 | } executed 369 times by 1 test: end of block Executed by:
| 369 | ||||||||||||||||||||||||||||||
530 | } | - | ||||||||||||||||||||||||||||||
531 | if (p != NULL && service != NULL) {
| 0-371 | ||||||||||||||||||||||||||||||
532 | if (pl == 0
| 0-371 | ||||||||||||||||||||||||||||||
533 | || (pl == 1 && p[0] == '*')) {
| 0-193 | ||||||||||||||||||||||||||||||
534 | *service = NULL; | - | ||||||||||||||||||||||||||||||
535 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
536 | *service = OPENSSL_strndup(p, pl); | - | ||||||||||||||||||||||||||||||
537 | if (*service == NULL)
| 0-371 | ||||||||||||||||||||||||||||||
538 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||||||||
539 | } executed 371 times by 1 test: end of block Executed by:
| 371 | ||||||||||||||||||||||||||||||
540 | } | - | ||||||||||||||||||||||||||||||
541 | - | |||||||||||||||||||||||||||||||
542 | return 1; executed 371 times by 1 test: return 1; Executed by:
| 371 | ||||||||||||||||||||||||||||||
543 | amb_err: | - | ||||||||||||||||||||||||||||||
544 | BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_AMBIGUOUS_HOST_OR_SERVICE); | - | ||||||||||||||||||||||||||||||
545 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
546 | spec_err: | - | ||||||||||||||||||||||||||||||
547 | BIOerr(BIO_F_BIO_PARSE_HOSTSERV, BIO_R_MALFORMED_HOST_OR_SERVICE); | - | ||||||||||||||||||||||||||||||
548 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
549 | memerr: | - | ||||||||||||||||||||||||||||||
550 | BIOerr(BIO_F_BIO_PARSE_HOSTSERV, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||
551 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
552 | } | - | ||||||||||||||||||||||||||||||
553 | - | |||||||||||||||||||||||||||||||
554 | /* addrinfo_wrap is used to build our own addrinfo "chain". | - | ||||||||||||||||||||||||||||||
555 | * (it has only one entry, so calling it a chain may be a stretch) | - | ||||||||||||||||||||||||||||||
556 | * It should ONLY be called when getaddrinfo() and friends | - | ||||||||||||||||||||||||||||||
557 | * aren't available, OR when dealing with a non IP protocol | - | ||||||||||||||||||||||||||||||
558 | * family, such as AF_UNIX | - | ||||||||||||||||||||||||||||||
559 | * | - | ||||||||||||||||||||||||||||||
560 | * the return value is 1 on success, or 0 on failure, which | - | ||||||||||||||||||||||||||||||
561 | * only happens if a memory allocation error occurred. | - | ||||||||||||||||||||||||||||||
562 | */ | - | ||||||||||||||||||||||||||||||
563 | static int addrinfo_wrap(int family, int socktype, | - | ||||||||||||||||||||||||||||||
564 | const void *where, size_t wherelen, | - | ||||||||||||||||||||||||||||||
565 | unsigned short port, | - | ||||||||||||||||||||||||||||||
566 | BIO_ADDRINFO **bai) | - | ||||||||||||||||||||||||||||||
567 | { | - | ||||||||||||||||||||||||||||||
568 | if ((*bai = OPENSSL_zalloc(sizeof(**bai))) == NULL) {
| 0 | ||||||||||||||||||||||||||||||
569 | BIOerr(BIO_F_ADDRINFO_WRAP, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||
570 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
571 | } | - | ||||||||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||||||||
573 | (*bai)->bai_family = family; | - | ||||||||||||||||||||||||||||||
574 | (*bai)->bai_socktype = socktype; | - | ||||||||||||||||||||||||||||||
575 | if (socktype == SOCK_STREAM)
| 0 | ||||||||||||||||||||||||||||||
576 | (*bai)->bai_protocol = IPPROTO_TCP; never executed: (*bai)->ai_protocol = IPPROTO_TCP ; | 0 | ||||||||||||||||||||||||||||||
577 | if (socktype == SOCK_DGRAM)
| 0 | ||||||||||||||||||||||||||||||
578 | (*bai)->bai_protocol = IPPROTO_UDP; never executed: (*bai)->ai_protocol = IPPROTO_UDP ; | 0 | ||||||||||||||||||||||||||||||
579 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
580 | if (family == AF_UNIX)
| 0 | ||||||||||||||||||||||||||||||
581 | (*bai)->bai_protocol = 0; never executed: (*bai)->ai_protocol = 0; | 0 | ||||||||||||||||||||||||||||||
582 | #endif | - | ||||||||||||||||||||||||||||||
583 | { | - | ||||||||||||||||||||||||||||||
584 | /* Magic: We know that BIO_ADDR_sockaddr_noconst is really | - | ||||||||||||||||||||||||||||||
585 | just an advanced cast of BIO_ADDR* to struct sockaddr * | - | ||||||||||||||||||||||||||||||
586 | by the power of union, so while it may seem that we're | - | ||||||||||||||||||||||||||||||
587 | creating a memory leak here, we are not. It will be | - | ||||||||||||||||||||||||||||||
588 | all right. */ | - | ||||||||||||||||||||||||||||||
589 | BIO_ADDR *addr = BIO_ADDR_new(); | - | ||||||||||||||||||||||||||||||
590 | if (addr != NULL) {
| 0 | ||||||||||||||||||||||||||||||
591 | BIO_ADDR_rawmake(addr, family, where, wherelen, port); | - | ||||||||||||||||||||||||||||||
592 | (*bai)->bai_addr = BIO_ADDR_sockaddr_noconst(addr); | - | ||||||||||||||||||||||||||||||
593 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
594 | } | - | ||||||||||||||||||||||||||||||
595 | (*bai)->bai_next = NULL; | - | ||||||||||||||||||||||||||||||
596 | if ((*bai)->bai_addr == NULL) {
| 0 | ||||||||||||||||||||||||||||||
597 | BIO_ADDRINFO_free(*bai); | - | ||||||||||||||||||||||||||||||
598 | *bai = NULL; | - | ||||||||||||||||||||||||||||||
599 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
600 | } | - | ||||||||||||||||||||||||||||||
601 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
602 | } | - | ||||||||||||||||||||||||||||||
603 | - | |||||||||||||||||||||||||||||||
604 | DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init) never executed: end of block | 0 | ||||||||||||||||||||||||||||||
605 | { | - | ||||||||||||||||||||||||||||||
606 | if (!OPENSSL_init_crypto(0, NULL))
| 0 | ||||||||||||||||||||||||||||||
607 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
608 | bio_lookup_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||||||||||||||||||||
609 | return bio_lookup_lock != NULL; never executed: return bio_lookup_lock != ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
610 | } | - | ||||||||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||||||||
612 | int BIO_lookup(const char *host, const char *service, | - | ||||||||||||||||||||||||||||||
613 | enum BIO_lookup_type lookup_type, | - | ||||||||||||||||||||||||||||||
614 | int family, int socktype, BIO_ADDRINFO **res) | - | ||||||||||||||||||||||||||||||
615 | { | - | ||||||||||||||||||||||||||||||
616 | return BIO_lookup_ex(host, service, lookup_type, family, socktype, 0, res); executed 4 times by 1 test: return BIO_lookup_ex(host, service, lookup_type, family, socktype, 0, res); Executed by:
| 4 | ||||||||||||||||||||||||||||||
617 | } | - | ||||||||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||||||||
619 | /*- | - | ||||||||||||||||||||||||||||||
620 | * BIO_lookup_ex - look up the node and service you want to connect to. | - | ||||||||||||||||||||||||||||||
621 | * @node: the node you want to connect to. | - | ||||||||||||||||||||||||||||||
622 | * @service: the service you want to connect to. | - | ||||||||||||||||||||||||||||||
623 | * @lookup_type: declare intent with the result, client or server. | - | ||||||||||||||||||||||||||||||
624 | * @family: the address family you want to use. Use AF_UNSPEC for any, or | - | ||||||||||||||||||||||||||||||
625 | * AF_INET, AF_INET6 or AF_UNIX. | - | ||||||||||||||||||||||||||||||
626 | * @socktype: The socket type you want to use. Can be SOCK_STREAM, SOCK_DGRAM | - | ||||||||||||||||||||||||||||||
627 | * or 0 for all. | - | ||||||||||||||||||||||||||||||
628 | * @protocol: The protocol to use, e.g. IPPROTO_TCP or IPPROTO_UDP or 0 for all. | - | ||||||||||||||||||||||||||||||
629 | * Note that some platforms may not return IPPROTO_SCTP without | - | ||||||||||||||||||||||||||||||
630 | * explicitly requesting it (i.e. IPPROTO_SCTP may not be returned | - | ||||||||||||||||||||||||||||||
631 | * with 0 for the protocol) | - | ||||||||||||||||||||||||||||||
632 | * @res: Storage place for the resulting list of returned addresses | - | ||||||||||||||||||||||||||||||
633 | * | - | ||||||||||||||||||||||||||||||
634 | * This will do a lookup of the node and service that you want to connect to. | - | ||||||||||||||||||||||||||||||
635 | * It returns a linked list of different addresses you can try to connect to. | - | ||||||||||||||||||||||||||||||
636 | * | - | ||||||||||||||||||||||||||||||
637 | * When no longer needed you should call BIO_ADDRINFO_free() to free the result. | - | ||||||||||||||||||||||||||||||
638 | * | - | ||||||||||||||||||||||||||||||
639 | * The return value is 1 on success or 0 in case of error. | - | ||||||||||||||||||||||||||||||
640 | */ | - | ||||||||||||||||||||||||||||||
641 | int BIO_lookup_ex(const char *host, const char *service, int lookup_type, | - | ||||||||||||||||||||||||||||||
642 | int family, int socktype, int protocol, BIO_ADDRINFO **res) | - | ||||||||||||||||||||||||||||||
643 | { | - | ||||||||||||||||||||||||||||||
644 | int ret = 0; /* Assume failure */ | - | ||||||||||||||||||||||||||||||
645 | - | |||||||||||||||||||||||||||||||
646 | switch(family) { | - | ||||||||||||||||||||||||||||||
647 | case AF_INET: executed 2 times by 1 test: case 2 : Executed by:
| 2 | ||||||||||||||||||||||||||||||
648 | #ifdef AF_INET6 | - | ||||||||||||||||||||||||||||||
649 | case AF_INET6: executed 2 times by 1 test: case 10 : Executed by:
| 2 | ||||||||||||||||||||||||||||||
650 | #endif | - | ||||||||||||||||||||||||||||||
651 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
652 | case AF_UNIX: never executed: case 1 : | 0 | ||||||||||||||||||||||||||||||
653 | #endif | - | ||||||||||||||||||||||||||||||
654 | #ifdef AF_UNSPEC | - | ||||||||||||||||||||||||||||||
655 | case AF_UNSPEC: executed 367 times by 1 test: case 0 : Executed by:
| 367 | ||||||||||||||||||||||||||||||
656 | #endif | - | ||||||||||||||||||||||||||||||
657 | break; executed 371 times by 1 test: break; Executed by:
| 371 | ||||||||||||||||||||||||||||||
658 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
659 | BIOerr(BIO_F_BIO_LOOKUP_EX, BIO_R_UNSUPPORTED_PROTOCOL_FAMILY); | - | ||||||||||||||||||||||||||||||
660 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
661 | } | - | ||||||||||||||||||||||||||||||
662 | - | |||||||||||||||||||||||||||||||
663 | #ifdef AF_UNIX | - | ||||||||||||||||||||||||||||||
664 | if (family == AF_UNIX) {
| 0-371 | ||||||||||||||||||||||||||||||
665 | if (addrinfo_wrap(family, socktype, host, strlen(host), 0, res))
| 0 | ||||||||||||||||||||||||||||||
666 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
667 | else | - | ||||||||||||||||||||||||||||||
668 | BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_MALLOC_FAILURE); never executed: ERR_put_error(32,(143),((1|64)),__FILE__,668); | 0 | ||||||||||||||||||||||||||||||
669 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
670 | } | - | ||||||||||||||||||||||||||||||
671 | #endif | - | ||||||||||||||||||||||||||||||
672 | - | |||||||||||||||||||||||||||||||
673 | if (BIO_sock_init() != 1)
| 0-371 | ||||||||||||||||||||||||||||||
674 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
675 | - | |||||||||||||||||||||||||||||||
676 | if (1) { | - | ||||||||||||||||||||||||||||||
677 | #ifdef AI_PASSIVE | - | ||||||||||||||||||||||||||||||
678 | int gai_ret = 0; | - | ||||||||||||||||||||||||||||||
679 | struct addrinfo hints; | - | ||||||||||||||||||||||||||||||
680 | - | |||||||||||||||||||||||||||||||
681 | memset(&hints, 0, sizeof(hints)); | - | ||||||||||||||||||||||||||||||
682 | - | |||||||||||||||||||||||||||||||
683 | hints.ai_family = family; | - | ||||||||||||||||||||||||||||||
684 | hints.ai_socktype = socktype; | - | ||||||||||||||||||||||||||||||
685 | hints.ai_protocol = protocol; | - | ||||||||||||||||||||||||||||||
686 | - | |||||||||||||||||||||||||||||||
687 | if (lookup_type == BIO_LOOKUP_SERVER)
| 178-193 | ||||||||||||||||||||||||||||||
688 | hints.ai_flags |= AI_PASSIVE; executed 178 times by 1 test: hints.ai_flags |= 0x0001 ; Executed by:
| 178 | ||||||||||||||||||||||||||||||
689 | - | |||||||||||||||||||||||||||||||
690 | /* Note that |res| SHOULD be a 'struct addrinfo **' thanks to | - | ||||||||||||||||||||||||||||||
691 | * macro magic in bio_lcl.h | - | ||||||||||||||||||||||||||||||
692 | */ | - | ||||||||||||||||||||||||||||||
693 | switch ((gai_ret = getaddrinfo(host, service, &hints, res))) { | - | ||||||||||||||||||||||||||||||
694 | # ifdef EAI_SYSTEM | - | ||||||||||||||||||||||||||||||
695 | case EAI_SYSTEM: never executed: case -11 : | 0 | ||||||||||||||||||||||||||||||
696 | SYSerr(SYS_F_GETADDRINFO, get_last_socket_error()); | - | ||||||||||||||||||||||||||||||
697 | BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB); | - | ||||||||||||||||||||||||||||||
698 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
699 | # endif | - | ||||||||||||||||||||||||||||||
700 | case 0: executed 371 times by 1 test: case 0: Executed by:
| 371 | ||||||||||||||||||||||||||||||
701 | ret = 1; /* Success */ | - | ||||||||||||||||||||||||||||||
702 | break; executed 371 times by 1 test: break; Executed by:
| 371 | ||||||||||||||||||||||||||||||
703 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
704 | BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_SYS_LIB); | - | ||||||||||||||||||||||||||||||
705 | ERR_add_error_data(1, gai_strerror(gai_ret)); | - | ||||||||||||||||||||||||||||||
706 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
707 | } | - | ||||||||||||||||||||||||||||||
708 | } else { | - | ||||||||||||||||||||||||||||||
709 | #endif | - | ||||||||||||||||||||||||||||||
710 | const struct hostent *he; | - | ||||||||||||||||||||||||||||||
711 | /* | - | ||||||||||||||||||||||||||||||
712 | * Because struct hostent is defined for 32-bit pointers only with | - | ||||||||||||||||||||||||||||||
713 | * VMS C, we need to make sure that '&he_fallback_address' and | - | ||||||||||||||||||||||||||||||
714 | * '&he_fallback_addresses' are 32-bit pointers | - | ||||||||||||||||||||||||||||||
715 | */ | - | ||||||||||||||||||||||||||||||
716 | #if defined(OPENSSL_SYS_VMS) && defined(__DECC) | - | ||||||||||||||||||||||||||||||
717 | # pragma pointer_size save | - | ||||||||||||||||||||||||||||||
718 | # pragma pointer_size 32 | - | ||||||||||||||||||||||||||||||
719 | #endif | - | ||||||||||||||||||||||||||||||
720 | /* Windows doesn't seem to have in_addr_t */ | - | ||||||||||||||||||||||||||||||
721 | #ifdef OPENSSL_SYS_WINDOWS | - | ||||||||||||||||||||||||||||||
722 | static uint32_t he_fallback_address; | - | ||||||||||||||||||||||||||||||
723 | static const char *he_fallback_addresses[] = | - | ||||||||||||||||||||||||||||||
724 | { (char *)&he_fallback_address, NULL }; | - | ||||||||||||||||||||||||||||||
725 | #else | - | ||||||||||||||||||||||||||||||
726 | static in_addr_t he_fallback_address; | - | ||||||||||||||||||||||||||||||
727 | static const char *he_fallback_addresses[] = | - | ||||||||||||||||||||||||||||||
728 | { (char *)&he_fallback_address, NULL }; | - | ||||||||||||||||||||||||||||||
729 | #endif | - | ||||||||||||||||||||||||||||||
730 | static const struct hostent he_fallback = | - | ||||||||||||||||||||||||||||||
731 | { NULL, NULL, AF_INET, sizeof(he_fallback_address), | - | ||||||||||||||||||||||||||||||
732 | (char **)&he_fallback_addresses }; | - | ||||||||||||||||||||||||||||||
733 | #if defined(OPENSSL_SYS_VMS) && defined(__DECC) | - | ||||||||||||||||||||||||||||||
734 | # pragma pointer_size restore | - | ||||||||||||||||||||||||||||||
735 | #endif | - | ||||||||||||||||||||||||||||||
736 | - | |||||||||||||||||||||||||||||||
737 | struct servent *se; | - | ||||||||||||||||||||||||||||||
738 | /* Apparently, on WIN64, s_proto and s_port have traded places... */ | - | ||||||||||||||||||||||||||||||
739 | #ifdef _WIN64 | - | ||||||||||||||||||||||||||||||
740 | struct servent se_fallback = { NULL, NULL, NULL, 0 }; | - | ||||||||||||||||||||||||||||||
741 | #else | - | ||||||||||||||||||||||||||||||
742 | struct servent se_fallback = { NULL, NULL, 0, NULL }; | - | ||||||||||||||||||||||||||||||
743 | #endif | - | ||||||||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||||||||
745 | if (!RUN_ONCE(&bio_lookup_init, do_bio_lookup_init)) {
| 0 | ||||||||||||||||||||||||||||||
746 | BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||
747 | ret = 0; | - | ||||||||||||||||||||||||||||||
748 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
749 | } | - | ||||||||||||||||||||||||||||||
750 | - | |||||||||||||||||||||||||||||||
751 | CRYPTO_THREAD_write_lock(bio_lookup_lock); | - | ||||||||||||||||||||||||||||||
752 | he_fallback_address = INADDR_ANY; | - | ||||||||||||||||||||||||||||||
753 | if (host == NULL) {
| 0 | ||||||||||||||||||||||||||||||
754 | he = &he_fallback; | - | ||||||||||||||||||||||||||||||
755 | switch(lookup_type) { | - | ||||||||||||||||||||||||||||||
756 | case BIO_LOOKUP_CLIENT: never executed: case BIO_LOOKUP_CLIENT: | 0 | ||||||||||||||||||||||||||||||
757 | he_fallback_address = INADDR_LOOPBACK; | - | ||||||||||||||||||||||||||||||
758 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
759 | case BIO_LOOKUP_SERVER: never executed: case BIO_LOOKUP_SERVER: | 0 | ||||||||||||||||||||||||||||||
760 | he_fallback_address = INADDR_ANY; | - | ||||||||||||||||||||||||||||||
761 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
762 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||
763 | /* We forgot to handle a lookup type! */ | - | ||||||||||||||||||||||||||||||
764 | assert("We forgot to handle a lookup type!" == NULL); | - | ||||||||||||||||||||||||||||||
765 | BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_INTERNAL_ERROR); | - | ||||||||||||||||||||||||||||||
766 | ret = 0; | - | ||||||||||||||||||||||||||||||
767 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
768 | } | - | ||||||||||||||||||||||||||||||
769 | } else { | - | ||||||||||||||||||||||||||||||
770 | he = gethostbyname(host); | - | ||||||||||||||||||||||||||||||
771 | - | |||||||||||||||||||||||||||||||
772 | if (he == NULL) {
| 0 | ||||||||||||||||||||||||||||||
773 | #ifndef OPENSSL_SYS_WINDOWS | - | ||||||||||||||||||||||||||||||
774 | /* | - | ||||||||||||||||||||||||||||||
775 | * This might be misleading, because h_errno is used as if | - | ||||||||||||||||||||||||||||||
776 | * it was errno. To minimize mixup add 1000. Underlying | - | ||||||||||||||||||||||||||||||
777 | * reason for this is that hstrerror is declared obsolete, | - | ||||||||||||||||||||||||||||||
778 | * not to mention that a) h_errno is not always guaranteed | - | ||||||||||||||||||||||||||||||
779 | * to be meaningless; b) hstrerror can reside in yet another | - | ||||||||||||||||||||||||||||||
780 | * library, linking for sake of hstrerror is an overkill; | - | ||||||||||||||||||||||||||||||
781 | * c) this path is not executed on contemporary systems | - | ||||||||||||||||||||||||||||||
782 | * anyway [above getaddrinfo/gai_strerror is]. We just let | - | ||||||||||||||||||||||||||||||
783 | * system administrator figure this out... | - | ||||||||||||||||||||||||||||||
784 | */ | - | ||||||||||||||||||||||||||||||
785 | SYSerr(SYS_F_GETHOSTBYNAME, 1000 + h_errno); | - | ||||||||||||||||||||||||||||||
786 | #else | - | ||||||||||||||||||||||||||||||
787 | SYSerr(SYS_F_GETHOSTBYNAME, WSAGetLastError()); | - | ||||||||||||||||||||||||||||||
788 | #endif | - | ||||||||||||||||||||||||||||||
789 | ret = 0; | - | ||||||||||||||||||||||||||||||
790 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
791 | } | - | ||||||||||||||||||||||||||||||
792 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
793 | - | |||||||||||||||||||||||||||||||
794 | if (service == NULL) {
| 0 | ||||||||||||||||||||||||||||||
795 | se_fallback.s_port = 0; | - | ||||||||||||||||||||||||||||||
796 | se_fallback.s_proto = NULL; | - | ||||||||||||||||||||||||||||||
797 | se = &se_fallback; | - | ||||||||||||||||||||||||||||||
798 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
799 | char *endp = NULL; | - | ||||||||||||||||||||||||||||||
800 | long portnum = strtol(service, &endp, 10); | - | ||||||||||||||||||||||||||||||
801 | - | |||||||||||||||||||||||||||||||
802 | /* | - | ||||||||||||||||||||||||||||||
803 | * Because struct servent is defined for 32-bit pointers only with | - | ||||||||||||||||||||||||||||||
804 | * VMS C, we need to make sure that 'proto' is a 32-bit pointer. | - | ||||||||||||||||||||||||||||||
805 | */ | - | ||||||||||||||||||||||||||||||
806 | #if defined(OPENSSL_SYS_VMS) && defined(__DECC) | - | ||||||||||||||||||||||||||||||
807 | # pragma pointer_size save | - | ||||||||||||||||||||||||||||||
808 | # pragma pointer_size 32 | - | ||||||||||||||||||||||||||||||
809 | #endif | - | ||||||||||||||||||||||||||||||
810 | char *proto = NULL; | - | ||||||||||||||||||||||||||||||
811 | #if defined(OPENSSL_SYS_VMS) && defined(__DECC) | - | ||||||||||||||||||||||||||||||
812 | # pragma pointer_size restore | - | ||||||||||||||||||||||||||||||
813 | #endif | - | ||||||||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||||||||
815 | switch (socktype) { | - | ||||||||||||||||||||||||||||||
816 | case SOCK_STREAM: never executed: case SOCK_STREAM : | 0 | ||||||||||||||||||||||||||||||
817 | proto = "tcp"; | - | ||||||||||||||||||||||||||||||
818 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
819 | case SOCK_DGRAM: never executed: case SOCK_DGRAM : | 0 | ||||||||||||||||||||||||||||||
820 | proto = "udp"; | - | ||||||||||||||||||||||||||||||
821 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
822 | } | - | ||||||||||||||||||||||||||||||
823 | - | |||||||||||||||||||||||||||||||
824 | if (endp != service && *endp == '\0'
| 0 | ||||||||||||||||||||||||||||||
825 | && portnum > 0 && portnum < 65536) {
| 0 | ||||||||||||||||||||||||||||||
826 | se_fallback.s_port = htons((unsigned short)portnum); never executed: __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); never executed: __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc");
| 0 | ||||||||||||||||||||||||||||||
827 | se_fallback.s_proto = proto; | - | ||||||||||||||||||||||||||||||
828 | se = &se_fallback; | - | ||||||||||||||||||||||||||||||
829 | } else if (endp == service) { never executed: end of block
| 0 | ||||||||||||||||||||||||||||||
830 | se = getservbyname(service, proto); | - | ||||||||||||||||||||||||||||||
831 | - | |||||||||||||||||||||||||||||||
832 | if (se == NULL) {
| 0 | ||||||||||||||||||||||||||||||
833 | #ifndef OPENSSL_SYS_WINDOWS | - | ||||||||||||||||||||||||||||||
834 | SYSerr(SYS_F_GETSERVBYNAME, errno); | - | ||||||||||||||||||||||||||||||
835 | #else | - | ||||||||||||||||||||||||||||||
836 | SYSerr(SYS_F_GETSERVBYNAME, WSAGetLastError()); | - | ||||||||||||||||||||||||||||||
837 | #endif | - | ||||||||||||||||||||||||||||||
838 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
839 | } | - | ||||||||||||||||||||||||||||||
840 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||
841 | BIOerr(BIO_F_BIO_LOOKUP_EX, BIO_R_MALFORMED_HOST_OR_SERVICE); | - | ||||||||||||||||||||||||||||||
842 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
843 | } | - | ||||||||||||||||||||||||||||||
844 | } | - | ||||||||||||||||||||||||||||||
845 | - | |||||||||||||||||||||||||||||||
846 | *res = NULL; | - | ||||||||||||||||||||||||||||||
847 | - | |||||||||||||||||||||||||||||||
848 | { | - | ||||||||||||||||||||||||||||||
849 | /* | - | ||||||||||||||||||||||||||||||
850 | * Because hostent::h_addr_list is an array of 32-bit pointers with VMS C, | - | ||||||||||||||||||||||||||||||
851 | * we must make sure our iterator designates the same element type, hence | - | ||||||||||||||||||||||||||||||
852 | * the pointer size dance. | - | ||||||||||||||||||||||||||||||
853 | */ | - | ||||||||||||||||||||||||||||||
854 | #if defined(OPENSSL_SYS_VMS) && defined(__DECC) | - | ||||||||||||||||||||||||||||||
855 | # pragma pointer_size save | - | ||||||||||||||||||||||||||||||
856 | # pragma pointer_size 32 | - | ||||||||||||||||||||||||||||||
857 | #endif | - | ||||||||||||||||||||||||||||||
858 | char **addrlistp; | - | ||||||||||||||||||||||||||||||
859 | #if defined(OPENSSL_SYS_VMS) && defined(__DECC) | - | ||||||||||||||||||||||||||||||
860 | # pragma pointer_size restore | - | ||||||||||||||||||||||||||||||
861 | #endif | - | ||||||||||||||||||||||||||||||
862 | size_t addresses; | - | ||||||||||||||||||||||||||||||
863 | BIO_ADDRINFO *tmp_bai = NULL; | - | ||||||||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||||||||
865 | /* The easiest way to create a linked list from an | - | ||||||||||||||||||||||||||||||
866 | array is to start from the back */ | - | ||||||||||||||||||||||||||||||
867 | for(addrlistp = he->h_addr_list; *addrlistp != NULL;
| 0 | ||||||||||||||||||||||||||||||
868 | addrlistp++) | - | ||||||||||||||||||||||||||||||
869 | ; never executed: ; | 0 | ||||||||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||||||||
871 | for(addresses = addrlistp - he->h_addr_list; | - | ||||||||||||||||||||||||||||||
872 | addrlistp--, addresses-- > 0; ) {
| 0 | ||||||||||||||||||||||||||||||
873 | if (!addrinfo_wrap(he->h_addrtype, socktype,
| 0 | ||||||||||||||||||||||||||||||
874 | *addrlistp, he->h_length,
| 0 | ||||||||||||||||||||||||||||||
875 | se->s_port, &tmp_bai))
| 0 | ||||||||||||||||||||||||||||||
876 | goto addrinfo_malloc_err; never executed: goto addrinfo_malloc_err; | 0 | ||||||||||||||||||||||||||||||
877 | tmp_bai->bai_next = *res; | - | ||||||||||||||||||||||||||||||
878 | *res = tmp_bai; | - | ||||||||||||||||||||||||||||||
879 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
880 | addrinfo_malloc_err: | - | ||||||||||||||||||||||||||||||
881 | BIO_ADDRINFO_free(*res); | - | ||||||||||||||||||||||||||||||
882 | *res = NULL; | - | ||||||||||||||||||||||||||||||
883 | BIOerr(BIO_F_BIO_LOOKUP_EX, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||||||||
884 | ret = 0; | - | ||||||||||||||||||||||||||||||
885 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
886 | } | - | ||||||||||||||||||||||||||||||
887 | - | |||||||||||||||||||||||||||||||
888 | ret = 1; | - | ||||||||||||||||||||||||||||||
889 | } | - | ||||||||||||||||||||||||||||||
890 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||||||||||||||
891 | CRYPTO_THREAD_unlock(bio_lookup_lock); | - | ||||||||||||||||||||||||||||||
892 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
893 | - | |||||||||||||||||||||||||||||||
894 | return ret; executed 371 times by 1 test: return ret; Executed by:
| 371 | ||||||||||||||||||||||||||||||
895 | } | - | ||||||||||||||||||||||||||||||
896 | - | |||||||||||||||||||||||||||||||
897 | #endif /* OPENSSL_NO_SOCK */ | - | ||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |