Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

unix,win: Check bind receives right socket type

  • Loading branch information...
erickt authored and ry committed Sep 25, 2011
1 parent c260a39 commit 1d7e61fafaaed60005754ff0023bfc7f9a4c614a
Showing with 22 additions and 12 deletions.
  1. +8 −8 src/unix/tcp.c
  2. +10 −0 src/unix/udp.c
  3. +2 −2 src/win/tcp.c
  4. +2 −2 src/win/udp.c
@@ -76,26 +76,26 @@ static int uv__tcp_bind(uv_tcp_t* tcp,
}


int uv_tcp_bind(uv_tcp_t* tcp, struct sockaddr_in addr) {
if (addr.sin_family != AF_INET) {
uv_err_new(tcp->loop, EFAULT);
int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
if (handle->type != UV_TCP || addr.sin_family != AF_INET) {
uv_err_new(handle->loop, EFAULT);
return -1;
}

return uv__tcp_bind(tcp,
return uv__tcp_bind(handle,
AF_INET,
(struct sockaddr*)&addr,
sizeof(struct sockaddr_in));
}


int uv_tcp_bind6(uv_tcp_t* tcp, struct sockaddr_in6 addr) {
if (addr.sin6_family != AF_INET6) {
uv_err_new(tcp->loop, EFAULT);
int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) {
uv_err_new(handle->loop, EFAULT);
return -1;
}

return uv__tcp_bind(tcp,
return uv__tcp_bind(handle,
AF_INET6,
(struct sockaddr*)&addr,
sizeof(struct sockaddr_in6));
@@ -444,6 +444,11 @@ int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) {


int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags) {
if (handle->type != UV_UDP || addr.sin_family != AF_INET) {
uv_err_new(handle->loop, EFAULT);
return -1;
}

return uv__udp_bind(handle,
AF_INET,
(struct sockaddr*)&addr,
@@ -453,6 +458,11 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags) {


int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags) {
if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) {
uv_err_new(handle->loop, EFAULT);
return -1;
}

return uv__udp_bind(handle,
AF_INET6,
(struct sockaddr*)&addr,
@@ -196,7 +196,7 @@ static int uv__bind(uv_loop_t* loop, uv_tcp_t* handle, int domain,
int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
uv_loop_t* loop = handle->loop;

if (addr.sin_family != AF_INET) {
if (handle->type != UV_TCP || addr.sin_family != AF_INET) {
uv_set_sys_error(loop, WSAEFAULT);
return -1;
}
@@ -212,7 +212,7 @@ int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
uv_loop_t* loop = handle->loop;

if (addr.sin6_family != AF_INET6) {
if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) {
uv_set_sys_error(loop, WSAEFAULT);
return -1;
}
@@ -198,7 +198,7 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
unsigned int flags) {
uv_loop_t* loop = handle->loop;

if (addr.sin_family != AF_INET) {
if (handle->type != UV_UDP || addr.sin_family != AF_INET) {
uv_set_sys_error(loop, WSAEFAULT);
return -1;
}
@@ -215,7 +215,7 @@ int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr,
unsigned int flags) {
uv_loop_t* loop = handle->loop;

if (addr.sin6_family != AF_INET6) {
if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) {
uv_set_sys_error(loop, WSAEFAULT);
return -1;
}

0 comments on commit 1d7e61f

Please sign in to comment.
You can’t perform that action at this time.