Commit bcf7fe2a authored by Eli Zaretskii's avatar Eli Zaretskii
Browse files

Improve error reporting as part of solving bug #13546 on MS-Windows.

 src/w32.c (sys_socket, sys_bind, sys_connect, sys_gethostname)
 (sys_gethostbyname, sys_getservbyname, sys_getpeername)
 (sys_shutdown, sys_setsockopt, sys_listen, sys_getsockname)
 (sys_accept, sys_recvfrom, sys_sendto, fcntl): In case of failure,
 make sure errno is set to an appropriate value.  (Bug#13546)
 (socket_to_fd): Add assertion against indexing fd_info[] with a
 value that is out of bounds.
 (sys_accept): If fd is negative, do not set up the child_process
 structure for reading.
parent 974c7646
2013-02-15 Eli Zaretskii <eliz@gnu.org>
* w32.c (sys_socket, sys_bind, sys_connect, sys_gethostname)
(sys_gethostbyname, sys_getservbyname, sys_getpeername)
(sys_shutdown, sys_setsockopt, sys_listen, sys_getsockname)
(sys_accept, sys_recvfrom, sys_sendto, fcntl): In case of failure,
make sure errno is set to an appropriate value. (Bug#13546)
(socket_to_fd): Add assertion against indexing fd_info[] with a
value that is out of bounds.
(sys_accept): If fd is negative, do not set up the child_process
structure for reading.
2013-02-14 Paul Eggert <eggert@cs.ucla.edu>
 
Backport GCPRO fix from trunk (Bug#13650).
......
......@@ -5655,7 +5655,7 @@ sys_socket (int af, int type, int protocol)
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return INVALID_SOCKET;
}
......@@ -5665,7 +5665,13 @@ sys_socket (int af, int type, int protocol)
s = pfn_socket (af, type, protocol);
if (s != INVALID_SOCKET)
return socket_to_fd (s);
{
int retval = socket_to_fd (s);
if (retval == -1)
errno = h_errno;
return retval;
}
set_errno ();
return -1;
......@@ -5732,6 +5738,7 @@ socket_to_fd (SOCKET s)
}
}
}
eassert (fd < MAXDESC);
fd_info[fd].hnd = (HANDLE) s;
/* set our own internal flags */
......@@ -5770,7 +5777,7 @@ sys_bind (int s, const struct sockaddr * addr, int namelen)
{
if (winsock_lib == NULL)
{
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5782,7 +5789,7 @@ sys_bind (int s, const struct sockaddr * addr, int namelen)
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5791,7 +5798,7 @@ sys_connect (int s, const struct sockaddr * name, int namelen)
{
if (winsock_lib == NULL)
{
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5803,7 +5810,7 @@ sys_connect (int s, const struct sockaddr * name, int namelen)
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5837,7 +5844,7 @@ sys_gethostname (char * name, int namelen)
if (namelen > MAX_COMPUTERNAME_LENGTH)
return !GetComputerName (name, (DWORD *)&namelen);
h_errno = EFAULT;
errno = h_errno = EFAULT;
return SOCKET_ERROR;
}
......@@ -5848,7 +5855,7 @@ sys_gethostbyname (const char * name)
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return NULL;
}
......@@ -5866,7 +5873,7 @@ sys_getservbyname (const char * name, const char * proto)
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return NULL;
}
......@@ -5882,7 +5889,7 @@ sys_getpeername (int s, struct sockaddr *addr, int * namelen)
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
......@@ -5894,7 +5901,7 @@ sys_getpeername (int s, struct sockaddr *addr, int * namelen)
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5903,7 +5910,7 @@ sys_shutdown (int s, int how)
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
......@@ -5915,7 +5922,7 @@ sys_shutdown (int s, int how)
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5924,7 +5931,7 @@ sys_setsockopt (int s, int level, int optname, const void * optval, int optlen)
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
......@@ -5937,7 +5944,7 @@ sys_setsockopt (int s, int level, int optname, const void * optval, int optlen)
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5946,7 +5953,7 @@ sys_listen (int s, int backlog)
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
......@@ -5960,7 +5967,7 @@ sys_listen (int s, int backlog)
fd_info[s].flags |= FILE_LISTEN;
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5969,7 +5976,7 @@ sys_getsockname (int s, struct sockaddr * name, int * namelen)
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
......@@ -5981,7 +5988,7 @@ sys_getsockname (int s, struct sockaddr * name, int * namelen)
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -5990,7 +5997,7 @@ sys_accept (int s, struct sockaddr * addr, int * addrlen)
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return -1;
}
......@@ -6002,13 +6009,20 @@ sys_accept (int s, struct sockaddr * addr, int * addrlen)
if (t == INVALID_SOCKET)
set_errno ();
else
fd = socket_to_fd (t);
{
fd = socket_to_fd (t);
if (fd < 0)
errno = h_errno; /* socket_to_fd sets h_errno */
}
fd_info[s].cp->status = STATUS_READ_ACKNOWLEDGED;
ResetEvent (fd_info[s].cp->char_avail);
if (fd >= 0)
{
fd_info[s].cp->status = STATUS_READ_ACKNOWLEDGED;
ResetEvent (fd_info[s].cp->char_avail);
}
return fd;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return -1;
}
......@@ -6018,7 +6032,7 @@ sys_recvfrom (int s, char * buf, int len, int flags,
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
......@@ -6030,7 +6044,7 @@ sys_recvfrom (int s, char * buf, int len, int flags,
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -6040,7 +6054,7 @@ sys_sendto (int s, const char * buf, int len, int flags,
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return SOCKET_ERROR;
}
......@@ -6052,7 +6066,7 @@ sys_sendto (int s, const char * buf, int len, int flags,
set_errno ();
return rc;
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......@@ -6063,7 +6077,7 @@ fcntl (int s, int cmd, int options)
{
if (winsock_lib == NULL)
{
h_errno = ENETDOWN;
errno = h_errno = ENETDOWN;
return -1;
}
......@@ -6086,7 +6100,7 @@ fcntl (int s, int cmd, int options)
return SOCKET_ERROR;
}
}
h_errno = ENOTSOCK;
errno = h_errno = ENOTSOCK;
return SOCKET_ERROR;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment