From d453fd0c24f3fba6a02e11bec6cee099fe1b5267 Mon Sep 17 00:00:00 2001
From: Sehrope Sarkuni <sehrope@jackdb.com>
Date: Wed, 10 Jun 2026 08:23:53 -0400
Subject: [PATCH v2 3/4] Fix off-by-one in pgwin32_select event array

The events array must hold up to 2*FD_SETSIZE socket events plus the
signal event. With full disjoint read and write fd sets the signal
event was written one element past the end of the array.
---
 src/backend/port/win32/socket.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c
index e16fd85ddd4..cf64983bece 100644
--- a/src/backend/port/win32/socket.c
+++ b/src/backend/port/win32/socket.c
@@ -516,9 +516,10 @@ pgwin32_send(SOCKET s, const void *buf, int len, int flags)
 int
 pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout)
 {
-	WSAEVENT	events[FD_SETSIZE * 2]; /* worst case is readfds totally
-										 * different from writefds, so
-										 * 2*FD_SETSIZE sockets */
+	WSAEVENT	events[FD_SETSIZE * 2 + 1]; /* worst case is readfds totally
+											 * different from writefds, so
+											 * 2*FD_SETSIZE sockets, plus one
+											 * for the signal event */
 	SOCKET		sockets[FD_SETSIZE * 2];
 	int			numevents = 0;
 	int			r;
-- 
2.17.1

