mirror of
https://github.com/postgres/postgres.git
synced 2025-07-23 03:21:12 +03:00
check socket creation errors against PGINVALID_SOCKET
Previously, in some places, socket creation errors were checked for negative values, which is not true for Windows because sockets are unsigned. This masked socket creation errors on Windows. Backpatch through 9.0. 8.4 doesn't have the infrastructure to fix this.
This commit is contained in:
@ -1673,7 +1673,7 @@ ident_inet(hbaPort *port)
|
||||
|
||||
sock_fd = socket(ident_serv->ai_family, ident_serv->ai_socktype,
|
||||
ident_serv->ai_protocol);
|
||||
if (sock_fd < 0)
|
||||
if (sock_fd == PGINVALID_SOCKET)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
@ -1753,7 +1753,7 @@ ident_inet(hbaPort *port)
|
||||
ident_response)));
|
||||
|
||||
ident_inet_done:
|
||||
if (sock_fd >= 0)
|
||||
if (sock_fd != PGINVALID_SOCKET)
|
||||
closesocket(sock_fd);
|
||||
pg_freeaddrinfo_all(remote_addr.addr.ss_family, ident_serv);
|
||||
pg_freeaddrinfo_all(local_addr.addr.ss_family, la);
|
||||
@ -2576,7 +2576,7 @@ CheckRADIUSAuth(Port *port)
|
||||
packet->length = htons(packet->length);
|
||||
|
||||
sock = socket(serveraddrs[0].ai_family, SOCK_DGRAM, 0);
|
||||
if (sock < 0)
|
||||
if (sock == PGINVALID_SOCKET)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("could not create RADIUS socket: %m")));
|
||||
|
@ -547,7 +547,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
|
||||
int error;
|
||||
|
||||
sock = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
|
||||
if (sock == SOCKET_ERROR)
|
||||
if (sock == INVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
while (n_ii < 1024)
|
||||
@ -670,7 +670,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
|
||||
total;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sock == -1)
|
||||
if (sock == PGINVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
while (n_buffer < 1024 * 100)
|
||||
@ -711,7 +711,7 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
|
||||
#ifdef HAVE_IPV6
|
||||
/* We'll need an IPv6 socket too for the SIOCGLIFNETMASK ioctls */
|
||||
sock6 = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (sock6 == -1)
|
||||
if (sock6 == PGINVALID_SOCKET)
|
||||
{
|
||||
free(buffer);
|
||||
close(sock);
|
||||
@ -788,10 +788,10 @@ pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data)
|
||||
char *ptr,
|
||||
*buffer = NULL;
|
||||
size_t n_buffer = 1024;
|
||||
int sock;
|
||||
pgsocket sock;
|
||||
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sock == -1)
|
||||
if (sock == PGINVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
while (n_buffer < 1024 * 100)
|
||||
|
@ -363,7 +363,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
|
||||
break;
|
||||
}
|
||||
|
||||
if ((fd = socket(addr->ai_family, SOCK_STREAM, 0)) < 0)
|
||||
if ((fd = socket(addr->ai_family, SOCK_STREAM, 0)) == PGINVALID_SOCKET)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
@ -606,7 +606,7 @@ StreamConnection(pgsocket server_fd, Port *port)
|
||||
port->raddr.salen = sizeof(port->raddr.addr);
|
||||
if ((port->sock = accept(server_fd,
|
||||
(struct sockaddr *) & port->raddr.addr,
|
||||
&port->raddr.salen)) < 0)
|
||||
&port->raddr.salen)) == PGINVALID_SOCKET)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
|
@ -132,7 +132,7 @@ int
|
||||
pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
|
||||
{
|
||||
static HANDLE waitevent = INVALID_HANDLE_VALUE;
|
||||
static SOCKET current_socket = -1;
|
||||
static SOCKET current_socket = INVALID_SOCKET;
|
||||
static int isUDP = 0;
|
||||
HANDLE events[2];
|
||||
int r;
|
||||
|
@ -1919,7 +1919,7 @@ ConnCreate(int serverFd)
|
||||
|
||||
if (StreamConnection(serverFd, port) != STATUS_OK)
|
||||
{
|
||||
if (port->sock >= 0)
|
||||
if (port->sock != PGINVALID_SOCKET)
|
||||
StreamClose(port->sock);
|
||||
ConnFree(port);
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user