GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Windows select fd_set overflow · oracle/graalpython@b07d624

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • graalpython/python-libposix/src
    • posix.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎graalpython/python-libposix/src/posix.c‎

Copy file name to clipboardExpand all lines: graalpython/python-libposix/src/posix.c
+27-9Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,27 @@ GP_EXPORT int32_t call_pipe2(int32_t *pipefd) {
10811081
return result;
10821082
}
10831083

1084+
static int win_fill_fd_set(fd_set *set, int32_t *fds, int32_t len) {
1085+
FD_ZERO(set);
1086+
for (int32_t i = 0; i < len; i++) {
1087+
SOCKET s = win_socket_from_fd(fds[i]);
1088+
int found = 0;
1089+
for (unsigned int j = 0; j < set->fd_count; j++) {
1090+
if (set->fd_array[j] == s) {
1091+
found = 1;
1092+
break;
1093+
}
1094+
}
1095+
if (!found) {
1096+
if (set->fd_count >= (unsigned int) FD_SETSIZE) {
1097+
return set_wsa_errno_from_error(WSAEINVAL);
1098+
}
1099+
set->fd_array[set->fd_count++] = s;
1100+
}
1101+
}
1102+
return 0;
1103+
}
1104+
10841105
GP_EXPORT int32_t call_select(int32_t nfds, int32_t* readfds, int32_t readfdsLen,
10851106
int32_t* writefds, int32_t writefdsLen, int32_t* errfds, int32_t errfdsLen,
10861107
int64_t timeoutSec, int64_t timeoutUsec, int8_t* selected) {
@@ -1092,17 +1113,14 @@ GP_EXPORT int32_t call_select(int32_t nfds, int32_t* readfds, int32_t readfdsLen
10921113
if (ensure_winsock() < 0) {
10931114
return -1;
10941115
}
1095-
FD_ZERO(&read_set);
1096-
FD_ZERO(&write_set);
1097-
FD_ZERO(&err_set);
1098-
for (int32_t i = 0; i < readfdsLen; i++) {
1099-
FD_SET(win_socket_from_fd(readfds[i]), &read_set);
1116+
if (win_fill_fd_set(&read_set, readfds, readfdsLen) < 0) {
1117+
return -1;
11001118
}
1101-
for (int32_t i = 0; i < writefdsLen; i++) {
1102-
FD_SET(win_socket_from_fd(writefds[i]), &write_set);
1119+
if (win_fill_fd_set(&write_set, writefds, writefdsLen) < 0) {
1120+
return -1;
11031121
}
1104-
for (int32_t i = 0; i < errfdsLen; i++) {
1105-
FD_SET(win_socket_from_fd(errfds[i]), &err_set);
1122+
if (win_fill_fd_set(&err_set, errfds, errfdsLen) < 0) {
1123+
return -1;
11061124
}
11071125
if (selectedLen > 0) {
11081126
memset(selected, 0, selectedLen * sizeof(*selected));

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.