Commit 363b604bff for openssl.org

commit 363b604bffc131e2ccda48b89d2d3ebf5eb285ad
Author: Mounir IDRASSI <mounir.idrassi@idrix.fr>
Date:   Thu Jul 30 09:24:59 2026 +0900

    Merge event masks for duplicate fds in the RIO poll builder

    ossl_rio_poll_builder_add_fd() documents duplicate registrations as
    equivalent to one registration with the logical OR of the requested
    directions. The poll(2) backend instead cleared an existing entry,
    making duplicate registrations last-writer-wins. The select(2)
    backend only adds bits to its fd_sets and already merges them.

    Clear the mask only when populating a new or reusable slot so an
    existing fd retains its previously requested events.

    Fixes https://github.com/openssl/openssl/issues/32116

    Assisted-by: Codex:gpt-5.6-sol

    Reviewed-by: Paul Yang <paulyang.inf@gmail.com>
    Reviewed-by: Jakub Zelenka <jakub.zelenka@openssl.foundation>
    MergeDate: Tue Aug 11 07:12:57 2026
    (Merged from https://github.com/openssl/openssl/pull/32117)

diff --git a/ssl/rio/poll_builder.c b/ssl/rio/poll_builder.c
index 28d93ee194..8088b17ad7 100644
--- a/ssl/rio/poll_builder.c
+++ b/ssl/rio/poll_builder.c
@@ -120,8 +120,10 @@ int ossl_rio_poll_builder_add_fd(RIO_POLL_BUILDER *rpb, int fd,

     assert((rpb->pfd_heap != NULL && rpb->pfd_heap == pfds) || (rpb->pfd_heap == NULL && rpb->pfds == pfds));
     assert(i <= rpb->pfd_num && rpb->pfd_num <= rpb->pfd_alloc);
+    /* Check the index first because an appended entry is uninitialised. */
+    if (i == rpb->pfd_num || pfds[i].fd == -1)
+        pfds[i].events = 0;
     pfds[i].fd = fd;
-    pfds[i].events = 0;

     if (want_read)
         pfds[i].events |= POLLIN;