summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/b_sock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/b_sock.c')
-rw-r--r--src/lib/libcrypto/bio/b_sock.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index 2a9159ec55..cd62f889ab 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -5,21 +5,21 @@
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA, 11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms 13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 * 15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in 16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed. 17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution 18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used. 19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or 20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package. 21 * in documentation (online or textual) provided with the package.
22 * 22 *
23 * Redistribution and use in source and binary forms, with or without 23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 24 * modification, are permitted provided that the following conditions
25 * are met: 25 * are met:
@@ -34,10 +34,10 @@
34 * Eric Young (eay@cryptsoft.com)" 34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library 35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-). 36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from 37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement: 38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 * 40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,7 +49,7 @@
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE. 51 * SUCH DAMAGE.
52 * 52 *
53 * The licence and distribution terms for any publically available version or 53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
@@ -240,7 +240,7 @@ BIO_sock_error(int sock)
240 * a cast it will choke the compiler: if you do have a cast then 240 * a cast it will choke the compiler: if you do have a cast then
241 * you can either go for (char *) or (void *). 241 * you can either go for (char *) or (void *).
242 */ 242 */
243 i = getsockopt(sock, SOL_SOCKET, SO_ERROR,(void *)&j,(void *)&size); 243 i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, (void *)&size);
244 if (i < 0) 244 if (i < 0)
245 return (1); 245 return (1);
246 else 246 else
@@ -317,12 +317,14 @@ static struct hostent
317 memset(ret->h_addr_list, 0, i*sizeof(char *)); 317 memset(ret->h_addr_list, 0, i*sizeof(char *));
318 318
319 j = strlen(a->h_name) + 1; 319 j = strlen(a->h_name) + 1;
320 if ((ret->h_name = OPENSSL_malloc(j)) == NULL) goto err; 320 if ((ret->h_name = OPENSSL_malloc(j)) == NULL)
321 memcpy((char *)ret->h_name, a->h_name, j); 321 goto err;
322 memcpy((char *)ret->h_name, a->h_name, j);
322 for (i = 0; a->h_aliases[i] != NULL; i++) { 323 for (i = 0; a->h_aliases[i] != NULL; i++) {
323 j = strlen(a->h_aliases[i]) + 1; 324 j = strlen(a->h_aliases[i]) + 1;
324 if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL) goto err; 325 if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL)
325 memcpy(ret->h_aliases[i], a->h_aliases[i], j); 326 goto err;
327 memcpy(ret->h_aliases[i], a->h_aliases[i], j);
326 } 328 }
327 ret->h_length = a->h_length; 329 ret->h_length = a->h_length;
328 ret->h_addrtype = a->h_addrtype; 330 ret->h_addrtype = a->h_addrtype;
@@ -367,7 +369,8 @@ ghbn_free(struct hostent *a)
367#endif 369#endif
368 370
369struct hostent 371struct hostent
370*BIO_gethostbyname(const char *name) { 372*BIO_gethostbyname(const char *name)
373{
371#if 1 374#if 1
372 /* Caching gethostbyname() results forever is wrong, 375 /* Caching gethostbyname() results forever is wrong,
373 * so we have to let the true gethostbyname() worry about this */ 376 * so we have to let the true gethostbyname() worry about this */
@@ -504,7 +507,7 @@ BIO_socket_ioctl(int fd, long type, void *arg)
504 int i; 507 int i;
505 508
506#ifdef __DJGPP__ 509#ifdef __DJGPP__
507 i = ioctl(fd, type,(char *)arg); 510 i = ioctl(fd, type, (char *)arg);
508#else 511#else
509# if defined(OPENSSL_SYS_VMS) 512# if defined(OPENSSL_SYS_VMS)
510 /* 2011-02-18 SMS. 513 /* 2011-02-18 SMS.
@@ -562,7 +565,7 @@ get_ip(const char *str, unsigned char ip[4])
562 num++; 565 num++;
563 ok = 0; 566 ok = 0;
564 } else if (c == '\0' && (num == 3) && ok) 567 } else if (c == '\0' && (num == 3) && ok)
565 break; 568 break;
566 else 569 else
567 return (0); 570 return (0);
568 } 571 }
@@ -618,8 +621,8 @@ BIO_get_accept_socket(char *host, int bind_mode)
618 static union { 621 static union {
619 void *p; 622 void *p;
620 int (WSAAPI *f)(const char *, const char *, 623 int (WSAAPI *f)(const char *, const char *,
621 const struct addrinfo *, 624 const struct addrinfo *,
622 struct addrinfo **); 625 struct addrinfo **);
623 } p_getaddrinfo = {NULL}; 626 } p_getaddrinfo = {NULL};
624 static union { 627 static union {
625 void *p; 628 void *p;
@@ -630,9 +633,10 @@ BIO_get_accept_socket(char *host, int bind_mode)
630 if (p_getaddrinfo.p == NULL) { 633 if (p_getaddrinfo.p == NULL) {
631 if ((p_getaddrinfo.p = DSO_global_lookup("getaddrinfo"))==NULL || 634 if ((p_getaddrinfo.p = DSO_global_lookup("getaddrinfo"))==NULL ||
632 (p_freeaddrinfo.p = DSO_global_lookup("freeaddrinfo"))==NULL) 635 (p_freeaddrinfo.p = DSO_global_lookup("freeaddrinfo"))==NULL)
633 p_getaddrinfo.p = (void*) - 1; 636 p_getaddrinfo.p = (void*) - 1;
634 } 637 }
635 if (p_getaddrinfo.p == (void *) - 1) break; 638 if (p_getaddrinfo.p == (void *) - 1)
639 break;
636 640
637 /* '::port' enforces IPv6 wildcard listener. Some OSes, 641 /* '::port' enforces IPv6 wildcard listener. Some OSes,
638 * e.g. Solaris, default to IPv6 without any hint. Also 642 * e.g. Solaris, default to IPv6 without any hint. Also
@@ -680,8 +684,7 @@ BIO_get_accept_socket(char *host, int bind_mode)
680 else { 684 else {
681 if (!BIO_get_host_ip(h, &(ip[0]))) 685 if (!BIO_get_host_ip(h, &(ip[0])))
682 goto err; 686 goto err;
683 l = (unsigned long) 687 l = (unsigned long)((unsigned long)ip[0]<<24L)|
684 ((unsigned long)ip[0]<<24L)|
685 ((unsigned long)ip[1]<<16L)| 688 ((unsigned long)ip[1]<<16L)|
686 ((unsigned long)ip[2]<< 8L)| 689 ((unsigned long)ip[2]<< 8L)|
687 ((unsigned long)ip[3]); 690 ((unsigned long)ip[3]);
@@ -701,7 +704,7 @@ again:
701 if (bind_mode == BIO_BIND_REUSEADDR) { 704 if (bind_mode == BIO_BIND_REUSEADDR) {
702 int i = 1; 705 int i = 1;
703 706
704 ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,(char *)&i, sizeof(i)); 707 ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&i, sizeof(i));
705 bind_mode = BIO_BIND_NORMAL; 708 bind_mode = BIO_BIND_NORMAL;
706 } 709 }
707#endif 710#endif
@@ -709,8 +712,7 @@ again:
709#ifdef SO_REUSEADDR 712#ifdef SO_REUSEADDR
710 err_num = errno; 713 err_num = errno;
711 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && 714 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
712 (err_num == EADDRINUSE)) 715 (err_num == EADDRINUSE)) {
713 {
714 client = server; 716 client = server;
715 if (h == NULL || strcmp(h, "*") == 0) { 717 if (h == NULL || strcmp(h, "*") == 0) {
716#if OPENSSL_USE_IPV6 718#if OPENSSL_USE_IPV6
@@ -807,15 +809,16 @@ BIO_accept(int sock, char **addr)
807 sa.len.s = 0; 809 sa.len.s = 0;
808 sa.len.i = sizeof(sa.from); 810 sa.len.i = sizeof(sa.from);
809 memset(&sa.from, 0, sizeof(sa.from)); 811 memset(&sa.from, 0, sizeof(sa.from));
810 ret = accept(sock, &sa.from.sa,(void *)&sa.len); 812 ret = accept(sock, &sa.from.sa, (void *)&sa.len);
811 if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) { 813 if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
812 OPENSSL_assert(sa.len.s <= sizeof(sa.from)); 814 OPENSSL_assert(sa.len.s <= sizeof(sa.from));
813 sa.len.i = (int)sa.len.s; 815 sa.len.i = (int)sa.len.s;
814 /* use sa.len.i from this point */ 816 /* use sa.len.i from this point */
815 } 817 }
816 if (ret == -1) { 818 if (ret == -1) {
817 if (BIO_sock_should_retry(ret)) return -2; 819 if (BIO_sock_should_retry(ret))
818 SYSerr(SYS_F_ACCEPT, errno); 820 return -2;
821 SYSerr(SYS_F_ACCEPT, errno);
819 BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR); 822 BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR);
820 goto end; 823 goto end;
821 } 824 }
@@ -830,7 +833,7 @@ BIO_accept(int sock, char **addr)
830 static union { 833 static union {
831 void *p; 834 void *p;
832 int (WSAAPI *f)(const struct sockaddr *, 835 int (WSAAPI *f)(const struct sockaddr *,
833 size_t/*socklen_t*/, char *, size_t, 836 size_t/*socklen_t*/, char *, size_t,
834 char *, size_t, int); 837 char *, size_t, int);
835 } p_getnameinfo = {NULL}; 838 } p_getnameinfo = {NULL};
836 /* 2nd argument to getnameinfo is specified to 839 /* 2nd argument to getnameinfo is specified to
@@ -900,7 +903,7 @@ BIO_set_tcp_ndelay(int s, int on)
900#endif 903#endif
901#endif 904#endif
902 905
903 ret = setsockopt(s, opt, TCP_NODELAY,(char *)&on, sizeof(on)); 906 ret = setsockopt(s, opt, TCP_NODELAY, (char *)&on, sizeof(on));
904#endif 907#endif
905 return (ret == 0); 908 return (ret == 0);
906} 909}