From c260a3964532120edcc071c22eb4bc9d8d09031d Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sun, 25 Sep 2011 16:16:07 -0700 Subject: [PATCH] unix,win: Check connect receives right socket type --- src/unix/tcp.c | 14 ++------------ src/win/tcp.c | 4 ++-- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/unix/tcp.c b/src/unix/tcp.c index 9f14c1b6c..8c3b27b8f 100644 --- a/src/unix/tcp.c +++ b/src/unix/tcp.c @@ -226,12 +226,7 @@ int uv_tcp_connect(uv_connect_t* req, saved_errno = errno; status = -1; - if (handle->type != UV_TCP) { - uv_err_new(handle->loop, EINVAL); - goto out; - } - - if (address.sin_family != AF_INET) { + if (handle->type != UV_TCP || address.sin_family != AF_INET) { uv_err_new(handle->loop, EINVAL); goto out; } @@ -258,12 +253,7 @@ int uv_tcp_connect6(uv_connect_t* req, saved_errno = errno; status = -1; - if (handle->type != UV_TCP) { - uv_err_new(handle->loop, EINVAL); - goto out; - } - - if (address.sin6_family != AF_INET6) { + if (handle->type != UV_TCP || address.sin6_family != AF_INET6) { uv_err_new(handle->loop, EINVAL); goto out; } diff --git a/src/win/tcp.c b/src/win/tcp.c index 783d5fb9a..d909eb301 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -484,7 +484,7 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, return -1; } - if (address.sin_family != AF_INET) { + if (handle->type != UV_TCP || address.sin_family != AF_INET) { uv_set_sys_error(loop, WSAEFAULT); return -1; } @@ -540,7 +540,7 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, return -1; } - if (address.sin6_family != AF_INET6) { + if (handle->type != UV_TCP || address.sin6_family != AF_INET6) { uv_set_sys_error(loop, WSAEFAULT); return -1; }