connect() now checks socket family

This commit is contained in:
Joseph Henry 2015-10-13 19:27:19 -04:00
parent 1fd04557c7
commit 71c6ec71e5
3 changed files with 12 additions and 7 deletions

View File

@ -951,7 +951,7 @@ void NetconEthernetTap::handle_listen(PhySocket *sock, void **uptr, struct liste
[I] EINVAL - Unknown protocol, or protocol family not available. [I] EINVAL - Unknown protocol, or protocol family not available.
[I] EINVAL - Invalid flags in type. [I] EINVAL - Invalid flags in type.
[I] EMFILE - Process file table overflow. [I] EMFILE - Process file table overflow.
[i] ENFILE - The system limit on the total number of open files has been reached. [?] ENFILE - The system limit on the total number of open files has been reached.
[X] ENOBUFS or ENOMEM - Insufficient memory is available. The socket cannot be created until sufficient resources are freed. [X] ENOBUFS or ENOMEM - Insufficient memory is available. The socket cannot be created until sufficient resources are freed.
[?] EPROTONOSUPPORT - The protocol type or the specified protocol is not supported within this domain. [?] EPROTONOSUPPORT - The protocol type or the specified protocol is not supported within this domain.
@ -1004,10 +1004,10 @@ void NetconEthernetTap::handle_socket(PhySocket *sock, void **uptr, struct socke
- := Not needed - := Not needed
[-] EACCES - For UNIX domain sockets, which are identified by pathname: Write permission is denied ... [-] EACCES - For UNIX domain sockets, which are identified by pathname: Write permission is denied ...
[ ] EACCES, EPERM - The user tried to connect to a broadcast address without having the socket broadcast flag enabled ... [?] EACCES, EPERM - The user tried to connect to a broadcast address without having the socket broadcast flag enabled ...
[i] EADDRINUSE - Local address is already in use. [i] EADDRINUSE - Local address is already in use.
[?] EAFNOSUPPORT - The passed address didn't have the correct address family in its sa_family field. [I] EAFNOSUPPORT - The passed address didn't have the correct address family in its sa_family field.
[ ] EAGAIN - No more free local ports or insufficient entries in the routing cache. [?] EAGAIN - No more free local ports or insufficient entries in the routing cache.
[ ] EALREADY - The socket is nonblocking and a previous connection attempt has not yet been completed. [ ] EALREADY - The socket is nonblocking and a previous connection attempt has not yet been completed.
[I] EBADF - The file descriptor is not a valid index in the descriptor table. [I] EBADF - The file descriptor is not a valid index in the descriptor table.
[ ] ECONNREFUSED - No-one listening on the remote address. [ ] ECONNREFUSED - No-one listening on the remote address.

View File

@ -607,6 +607,9 @@ int socket(SOCKET_SIG)
connect() intercept function */ connect() intercept function */
int connect(CONNECT_SIG) int connect(CONNECT_SIG)
{ {
struct sockaddr_in *connaddr;
connaddr = (struct sockaddr_in *) __addr;
#ifdef CHECKS #ifdef CHECKS
/* Check that this is a valid fd */ /* Check that this is a valid fd */
if(fcntl(__fd, F_GETFD) < 0) { if(fcntl(__fd, F_GETFD) < 0) {
@ -620,6 +623,11 @@ int connect(CONNECT_SIG)
errno = ENOTSOCK; errno = ENOTSOCK;
return -1; return -1;
} }
/* Check family */
if (connaddr->sin_family < 0 || connaddr->sin_family >= NPROTO){
errno = EAFNOSUPPORT;
return -1;
}
/* FIXME: Check that address is in user space, return EFAULT ? */ /* FIXME: Check that address is in user space, return EFAULT ? */
#endif #endif
@ -637,9 +645,6 @@ int connect(CONNECT_SIG)
return(realconnect(__fd, __addr, __len)); return(realconnect(__fd, __addr, __len));
} }
struct sockaddr_in *connaddr;
connaddr = (struct sockaddr_in *) __addr;
if(__addr != NULL && (connaddr->sin_family == AF_LOCAL if(__addr != NULL && (connaddr->sin_family == AF_LOCAL
|| connaddr->sin_family == PF_NETLINK || connaddr->sin_family == PF_NETLINK
|| connaddr->sin_family == AF_NETLINK || connaddr->sin_family == AF_NETLINK

Binary file not shown.