summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrent Cook <bcook@cvs.openbsd.org>2014-11-26 05:37:27 +0000
committerBrent Cook <bcook@cvs.openbsd.org>2014-11-26 05:37:27 +0000
commit007bf0a49fb2fdae50e4a134d793d9e90a2902ad (patch)
tree73845d78797ff9d28ff3591c4c504cd4a31ba5ff /lib
parentad0a252c4bb336462f90144782d97c3ac8f365c7 (diff)
normalize set/getsockopt usage.
Remove the remaining random casts on optval. Fixups for this can be handled by the portability layer all in once place. Remove remaining fake socklen_t unions, though beck@ points out that this also removes support for socklen_t changing its length at runtime. RIP. ok tedu@ beck@ miod@ deraadt@
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/bio/b_sock.c5
-rw-r--r--lib/libcrypto/bio/bss_conn.c4
-rw-r--r--lib/libcrypto/bio/bss_dgram.c63
3 files changed, 27 insertions, 45 deletions
diff --git a/lib/libcrypto/bio/b_sock.c b/lib/libcrypto/bio/b_sock.c
index 34e5d9830e2..8f3c58fda25 100644
--- a/lib/libcrypto/bio/b_sock.c
+++ b/lib/libcrypto/bio/b_sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: b_sock.c,v 1.58 2014/10/13 02:49:53 bcook Exp $ */
+/* $OpenBSD: b_sock.c,v 1.59 2014/11/26 05:37:26 bcook Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -318,8 +318,7 @@ again:
if (bind_mode == BIO_BIND_REUSEADDR) {
int i = 1;
- ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&i,
- sizeof(i));
+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
bind_mode = BIO_BIND_NORMAL;
}
if (bind(s, &server.sa, addrlen) == -1) {
diff --git a/lib/libcrypto/bio/bss_conn.c b/lib/libcrypto/bio/bss_conn.c
index e55fc2d163d..7f509366775 100644
--- a/lib/libcrypto/bio/bss_conn.c
+++ b/lib/libcrypto/bio/bss_conn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bss_conn.c,v 1.31 2014/11/21 18:15:40 deraadt Exp $ */
+/* $OpenBSD: bss_conn.c,v 1.32 2014/11/26 05:37:26 bcook Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -220,7 +220,7 @@ conn_state(BIO *b, BIO_CONNECT *c)
#if defined(SO_KEEPALIVE)
i = 1;
- i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE,(char *)&i, sizeof(i));
+ i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE, &i, sizeof(i));
if (i < 0) {
SYSerr(SYS_F_SOCKET, errno);
ERR_asprintf_error_data("host=%s:%s",
diff --git a/lib/libcrypto/bio/bss_dgram.c b/lib/libcrypto/bio/bss_dgram.c
index 8f7f945e739..9809eda92e3 100644
--- a/lib/libcrypto/bio/bss_dgram.c
+++ b/lib/libcrypto/bio/bss_dgram.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bss_dgram.c,v 1.34 2014/11/26 05:01:47 bcook Exp $ */
+/* $OpenBSD: bss_dgram.c,v 1.35 2014/11/26 05:37:26 bcook Exp $ */
/*
* DTLS implementation written by Nagendra Modadugu
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -244,21 +244,17 @@ dgram_adjust_rcv_timeout(BIO *b)
{
#if defined(SO_RCVTIMEO)
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
- union { size_t s;
- int i;
- } sz = {0};
/* Is a timer active? */
if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) {
struct timeval timenow, timeleft;
/* Read current socket timeout */
- sz.i = sizeof(data->socket_timeout);
+ socklen_t sz = sizeof(data->socket_timeout);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- &(data->socket_timeout), (void *)&sz) < 0) {
+ &(data->socket_timeout), &sz) < 0) {
perror("getsockopt");
- } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0)
- OPENSSL_assert(sz.s <= sizeof(data->socket_timeout));
+ }
/* Get current time */
get_current_time(&timenow);
@@ -469,17 +465,18 @@ dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
switch (addr.sa.sa_family) {
case AF_INET:
sockopt_val = IP_PMTUDISC_DO;
- if ((ret = setsockopt(b->num, IPPROTO_IP,
- IP_MTU_DISCOVER, &sockopt_val,
- sizeof(sockopt_val))) < 0)
+ ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER,
+ &sockopt_val, sizeof(sockopt_val));
+ if (ret < 0)
perror("setsockopt");
break;
#if defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
case AF_INET6:
sockopt_val = IPV6_PMTUDISC_DO;
- if ((ret = setsockopt(b->num, IPPROTO_IPV6,
+ ret = setsockopt(b->num, IPPROTO_IPV6,
IPV6_MTU_DISCOVER, &sockopt_val,
- sizeof(sockopt_val))) < 0)
+ sizeof(sockopt_val));
+ if (ret < 0)
perror("setsockopt");
break;
#endif
@@ -502,9 +499,9 @@ dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
sockopt_len = sizeof(sockopt_val);
switch (addr.sa.sa_family) {
case AF_INET:
- if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU,
- (void *)&sockopt_val, &sockopt_len)) < 0 ||
- sockopt_val < 0) {
+ ret = getsockopt(b->num, IPPROTO_IP, IP_MTU,
+ &sockopt_val, &sockopt_len);
+ if (ret < 0 || sockopt_val < 0) {
ret = 0;
} else {
/* we assume that the transport protocol is UDP and no
@@ -516,9 +513,9 @@ dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
break;
#if defined(IPV6_MTU)
case AF_INET6:
- if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU,
- (void *)&sockopt_val, &sockopt_len)) < 0 ||
- sockopt_val < 0) {
+ ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU,
+ &sockopt_val, &sockopt_len);
+ if (ret < 0 || sockopt_val < 0) {
ret = 0;
} else {
/* we assume that the transport protocol is UDP and no
@@ -626,20 +623,13 @@ default:
break;
case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT:
{
- union {
- size_t s;
- int i;
- } sz = {0};
- sz.i = sizeof(struct timeval);
+ socklen_t sz = sizeof(struct timeval);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- ptr, (void *)&sz) < 0) {
+ ptr, &sz) < 0) {
perror("getsockopt");
ret = -1;
- } else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) {
- OPENSSL_assert(sz.s <= sizeof(struct timeval));
- ret = (int)sz.s;
} else
- ret = sz.i;
+ ret = sz;
}
break;
#endif
@@ -653,20 +643,13 @@ default:
break;
case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT:
{
- union {
- size_t s;
- int i;
- } sz = {0};
- sz.i = sizeof(struct timeval);
+ socklen_t sz = sizeof(struct timeval);
if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- ptr, (void *)&sz) < 0) {
+ ptr, &sz) < 0) {
perror("getsockopt");
ret = -1;
- } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0) {
- OPENSSL_assert(sz.s <= sizeof(struct timeval));
- ret = (int)sz.s;
} else
- ret = sz.i;
+ ret = sz;
}
break;
#endif
@@ -1295,7 +1278,7 @@ dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr)
if (authkeyid.scact_keynumber > 0) {
authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1;
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
+ &authkeyid, sizeof(struct sctp_authkeyid));
if (ret < 0)
break;
}