Navigation Menu

Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix,win: Check bind receives right socket type
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt authored and ry committed Sep 28, 2011
1 parent c260a39 commit 1d7e61f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/unix/tcp.c
Expand Up @@ -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));
Expand Down
10 changes: 10 additions & 0 deletions src/unix/udp.c
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/win/tcp.c
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/win/udp.c
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 1d7e61f

Please sign in to comment.