* dtable.cc (dtable::init_std_file_from_handle): Mention that console
handles are kernel objects since Windows 8. * fhandler.h (enum conn_state): Add "listener" state. (class fhandler_socket): Drop listener status flag. (fhandler_socket::lseek): Return -1 and errno ESPIPE. (fhandler_serial::lseek): Ditto. * fhandler_socket.cc (fhandler_socket::listen): Set connect_state to listener. Add comment. (fhandler_socket::accept4): Explicitely check if the socket is listening and fail with EINVAL, if not. Explain why we have to do that. (fhandler_socket::recv_internal): Explicitely check if the socket is connected if it's a stream socket. Explain why we have to do that. (fhandler_socket::getpeereid): Drop now redundant test.
This commit is contained in:
@ -1180,8 +1180,7 @@ fhandler_socket::listen (int backlog)
|
||||
{
|
||||
if (get_addr_family () == AF_LOCAL && get_socket_type () == SOCK_STREAM)
|
||||
af_local_set_cred ();
|
||||
connect_state (connected);
|
||||
listener (true);
|
||||
connect_state (listener); /* gets set to connected on accepted socket. */
|
||||
}
|
||||
else
|
||||
set_winsock_errno ();
|
||||
@ -1195,7 +1194,17 @@ fhandler_socket::accept4 (struct sockaddr *peer, int *len, int flags)
|
||||
struct sockaddr_storage lpeer;
|
||||
int llen = sizeof (struct sockaddr_storage);
|
||||
|
||||
int res = 0;
|
||||
int res = (int) INVALID_SOCKET;
|
||||
|
||||
/* Windows event handling does not check for the validity of the desired
|
||||
flags so we have to do it here. */
|
||||
if (connect_state () != listener)
|
||||
{
|
||||
WSASetLastError (WSAEINVAL);
|
||||
set_winsock_errno ();
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (!(res = wait_for_events (FD_ACCEPT | FD_CLOSE, 0))
|
||||
&& (res = ::accept (get_socket (), (struct sockaddr *) &lpeer, &llen))
|
||||
== SOCKET_ERROR
|
||||
@ -1392,6 +1401,15 @@ fhandler_socket::recv_internal (LPWSAMSG wsamsg, bool use_recvmsg)
|
||||
static NO_COPY LPFN_WSARECVMSG WSARecvMsg;
|
||||
int orig_namelen = wsamsg->namelen;
|
||||
|
||||
/* Windows event handling does not check for the validity of the desired
|
||||
flags so we have to do it here. */
|
||||
if (get_socket_type () == SOCK_STREAM && connect_state () != connected)
|
||||
{
|
||||
WSASetLastError (WSAENOTCONN);
|
||||
set_winsock_errno ();
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
DWORD wait_flags = wsamsg->dwFlags;
|
||||
bool waitall = !!(wait_flags & MSG_WAITALL);
|
||||
wsamsg->dwFlags &= (MSG_OOB | MSG_PEEK | MSG_DONTROUTE);
|
||||
@ -2264,12 +2282,6 @@ fhandler_socket::getpeereid (pid_t *pid, uid_t *euid, gid_t *egid)
|
||||
set_errno (ENOTCONN);
|
||||
return -1;
|
||||
}
|
||||
if (sec_peer_pid == (pid_t) 0)
|
||||
{
|
||||
set_errno (ENOTCONN); /* Usually when calling getpeereid on
|
||||
accepting (instead of accepted) socket. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
myfault efault;
|
||||
if (efault.faulted (EFAULT))
|
||||
|
Reference in New Issue
Block a user