Skip to content

Commit

Permalink
Make BIO_sock_error return a proper error code when getsockopt fails
Browse files Browse the repository at this point in the history
BIO_sock_error() returned 1 when getsockopt() fails when it should
return the error code for that failure.

Additionally, the optlen parameter to getsockopt() has to point at
the size of the area that the optval parameter points at rather than
zero.  Some systems may forgive it being zero, but others don't.

Reviewed-by: Matt Caswell <matt@openssl.org>
  • Loading branch information
levitte committed Apr 28, 2016
1 parent d78df5d commit 2bd8c85
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crypto/bio/b_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int BIO_get_port(const char *str, unsigned short *port_ptr)
int BIO_sock_error(int sock)
{
int j = 0, i;
socklen_t size = 0;
socklen_t size = sizeof(j);

/*
* Note: under Windows the third parameter is of type (char *) whereas
Expand All @@ -151,7 +151,7 @@ int BIO_sock_error(int sock)
*/
i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, &size);
if (i < 0)
return (1);
return (get_last_socket_error());
else
return (j);
}
Expand Down

0 comments on commit 2bd8c85

Please sign in to comment.