Skip to content

Commit 29dc8eb

Browse files
bengotowclaude
andauthored
Prevent undefined behavior when socket descriptor exceeds FD_SETSIZE (#27)
Cherry-pick fix from upstream libetpan PR #427. When there are many open file descriptors (e.g., due to connection leaks or high concurrency), socket descriptors can exceed FD_SETSIZE (typically 1024). Using FD_SET with such descriptors causes undefined behavior and can corrupt memory or trigger runtime checks like glibc's __fdelt_chk. This fix adds a bounds check before FD_SET to fail gracefully instead of causing undefined behavior. Note: Only the bug fix is cherry-picked; the unrelated configure.ac optimization level change from the original PR is not included. Upstream: dinhvh/libetpan#427 Co-authored-by: Claude <noreply@anthropic.com>
1 parent cd47c42 commit 29dc8eb

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Vendor/libetpan/src/data-types/mailstream_ssl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ static int wait_SSL_connect(int s, int want_read, time_t timeout_seconds)
335335
timeout.tv_usec = 0;
336336
}
337337
#if defined(WIN32) || !USE_POLL
338+
if (s >= FD_SETSIZE) {
339+
return -1;
340+
}
338341
FD_ZERO(&fds);
339342
FD_SET(s, &fds);
340343
/* TODO: how to cancel this ? */

0 commit comments

Comments
 (0)