Blame SOURCES/0003-SSS_CLIENT-if-poll-returns-POLLNVAL-then-socket-is-a.patch

8ea3d3
From a40b25a3af29706c058ce5a02dd0ba294dbb6874 Mon Sep 17 00:00:00 2001
8ea3d3
From: Alexey Tikhonov <atikhono@redhat.com>
8ea3d3
Date: Wed, 8 Feb 2023 17:48:52 +0100
8ea3d3
Subject: [PATCH 3/4] SSS_CLIENT: if poll() returns POLLNVAL then socket is
8ea3d3
 alredy closed (or wasn't open) so it shouldn't be closed again. Otherwise
8ea3d3
 there is a risk to close "foreign" socket opened in another thread.
8ea3d3
MIME-Version: 1.0
8ea3d3
Content-Type: text/plain; charset=UTF-8
8ea3d3
Content-Transfer-Encoding: 8bit
8ea3d3
8ea3d3
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
8ea3d3
Reviewed-by: Sumit Bose <sbose@redhat.com>
8ea3d3
(cherry picked from commit ef93284b5a1f196425d9a61e8e24de8972240eb3)
8ea3d3
---
8ea3d3
 src/sss_client/common.c | 18 +++++++++++++++---
8ea3d3
 1 file changed, 15 insertions(+), 3 deletions(-)
8ea3d3
8ea3d3
diff --git a/src/sss_client/common.c b/src/sss_client/common.c
8ea3d3
index 27e09f6f3..c8ade645b 100644
8ea3d3
--- a/src/sss_client/common.c
8ea3d3
+++ b/src/sss_client/common.c
8ea3d3
@@ -159,7 +159,11 @@ static enum sss_status sss_cli_send_req(enum sss_cli_command cmd,
8ea3d3
             *errnop = ETIME;
8ea3d3
             break;
8ea3d3
         case 1:
8ea3d3
-            if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
8ea3d3
+            if (pfd.revents & (POLLERR | POLLHUP)) {
8ea3d3
+                *errnop = EPIPE;
8ea3d3
+            } else if (pfd.revents & POLLNVAL) {
8ea3d3
+                /* Invalid request: fd is not opened */
8ea3d3
+                sss_cli_sd = -1;
8ea3d3
                 *errnop = EPIPE;
8ea3d3
             } else if (!(pfd.revents & POLLOUT)) {
8ea3d3
                 *errnop = EBUSY;
8ea3d3
@@ -270,7 +274,11 @@ static enum sss_status sss_cli_recv_rep(enum sss_cli_command cmd,
8ea3d3
             if (pfd.revents & (POLLHUP)) {
8ea3d3
                 pollhup = true;
8ea3d3
             }
8ea3d3
-            if (pfd.revents & (POLLERR | POLLNVAL)) {
8ea3d3
+            if (pfd.revents & POLLERR) {
8ea3d3
+                *errnop = EPIPE;
8ea3d3
+            } else if (pfd.revents & POLLNVAL) {
8ea3d3
+                /* Invalid request: fd is not opened */
8ea3d3
+                sss_cli_sd = -1;
8ea3d3
                 *errnop = EPIPE;
8ea3d3
             } else if (!(pfd.revents & POLLIN)) {
8ea3d3
                 *errnop = EBUSY;
8ea3d3
@@ -721,7 +729,11 @@ static enum sss_status sss_cli_check_socket(int *errnop,
8ea3d3
             *errnop = ETIME;
8ea3d3
             break;
8ea3d3
         case 1:
8ea3d3
-            if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
8ea3d3
+            if (pfd.revents & (POLLERR | POLLHUP)) {
8ea3d3
+                *errnop = EPIPE;
8ea3d3
+            } else if (pfd.revents & POLLNVAL) {
8ea3d3
+                /* Invalid request: fd is not opened */
8ea3d3
+                sss_cli_sd = -1;
8ea3d3
                 *errnop = EPIPE;
8ea3d3
             } else if (!(pfd.revents & (POLLIN | POLLOUT))) {
8ea3d3
                 *errnop = EBUSY;
8ea3d3
-- 
8ea3d3
2.37.3
8ea3d3