public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ranier Vilela <[email protected]>
To: Pg Hackers <[email protected]>
Subject: Re: Windows sockets (select missing events?)
Date: Sat, 30 Dec 2023 10:40:11 -0300
Message-ID: <CAEudQArx03C3x2UDKjTrknFsxYmx3Bu+A6yyi59y1NRFi2s3xQ@mail.gmail.com> (raw)
In-Reply-To: <CAEudQAqjqkXXsjdKpmi=ry+JCfaKrFJO9NF1bP5CrtvZwh0uHg@mail.gmail.com>
References: <CAEudQAqjqkXXsjdKpmi=ry+JCfaKrFJO9NF1bP5CrtvZwh0uHg@mail.gmail.com>

Em qui., 28 de dez. de 2023 às 14:45, Ranier Vilela <[email protected]>
escreveu:

> Hi,
>
> The type of field fd_count is defined in winsock.h:
> typedef unsigned int    u_int;
>
> So in the struct fd_set,
> the field fd_count is unsigned int.
>
> The pgwin32_select  function has loops that use *int* as indices.
>
> Question: in Windows, the socket select function isn't missing some events?
>
> If not, It would be a good prevention practice, using the correct type,
> right?
>
> Patch attached.
>
Fix overflow with patch.

best regards,
Ranier Vilela


Attachments:

  [application/octet-stream] v1-001-fix-socket-select-events.patch (879B, ../CAEudQArx03C3x2UDKjTrknFsxYmx3Bu+A6yyi59y1NRFi2s3xQ@mail.gmail.com/3-v1-001-fix-socket-select-events.patch)
  download | inline diff:
diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c
index 9c339397d1..18dc8d9686 100644
--- a/src/backend/port/win32/socket.c
+++ b/src/backend/port/win32/socket.c
@@ -519,8 +519,8 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c
 										 * different from writefds, so
 										 * 2*FD_SETSIZE sockets */
 	SOCKET		sockets[FD_SETSIZE * 2];
-	int			numevents = 0;
-	int			i;
+	u_int		numevents = 0;
+	u_int		i;
 	int			r;
 	DWORD		timeoutval = WSA_INFINITE;
 	FD_SET		outreadfds;
@@ -618,7 +618,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c
 		{
 			TranslateSocketError();
 			/* release already-assigned event objects */
-			while (--i >= 0)
+			while (i-- >= 0)
 				WSAEventSelect(sockets[i], NULL, 0);
 			for (i = 0; i < numevents; i++)
 				WSACloseEvent(events[i]);

view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Windows sockets (select missing events?)
  In-Reply-To: <CAEudQArx03C3x2UDKjTrknFsxYmx3Bu+A6yyi59y1NRFi2s3xQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox