We were erroneously using select() in the client code. This code can run
in arbitrary apps and using select() means we can cause memory
corruption in the calling application.

Use poll() instead.

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York
>From 4cb12eda3231807efdc6aaa678b0734b18dc7763 Mon Sep 17 00:00:00 2001
From: Simo Sorce <sso...@redhat.com>
Date: Tue, 3 May 2011 12:15:07 -0400
Subject: [PATCH] clients: use poll instead of select

select is limited to fd numbers up to 1024, we need to use poll() here
to avoid causing memory corruption in the calling process.

Fixes: https://fedorahosted.org/sssd/ticket/861
---
 src/sss_client/common.c |   15 ++++++---------
 1 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/sss_client/common.c b/src/sss_client/common.c
index 0e5795f72997055c9c5502d3913f6467f9897dc6..c8a951597a6b46a625d50bc321d354214af615b1 100644
--- a/src/sss_client/common.c
+++ b/src/sss_client/common.c
@@ -499,6 +499,7 @@ static int sss_cli_open_socket(int *errnop, const char *socket_name)
     bool connected = false;
     unsigned int wait_time;
     unsigned int sleep_time;
+    time_t start_time = time(NULL);
     int ret;
     int sd;
 
@@ -527,8 +528,7 @@ static int sss_cli_open_socket(int *errnop, const char *socket_name)
     while (inprogress) {
         int connect_errno = 0;
         socklen_t errnosize;
-        struct timeval tv;
-        fd_set w_fds;
+        struct pollfd pfd;
 
         wait_time += sleep_time;
 
@@ -541,12 +541,10 @@ static int sss_cli_open_socket(int *errnop, const char *socket_name)
 
         switch(errno) {
         case EINPROGRESS:
-            FD_ZERO(&w_fds);
-            FD_SET(sd, &w_fds);
-            tv.tv_sec = SSS_CLI_SOCKET_TIMEOUT - wait_time;
-            tv.tv_usec = 0;
+            pfd.fd = sd;
+            pfd.events = POLLOUT;
 
-            ret = select(sd + 1, NULL, &w_fds, NULL, &tv);
+            ret = poll(&pfd, 1, SSS_CLI_SOCKET_TIMEOUT - wait_time);
 
             if (ret > 0) {
                 errnosize = sizeof(connect_errno);
@@ -557,8 +555,7 @@ static int sss_cli_open_socket(int *errnop, const char *socket_name)
                     break;
                 }
             }
-            wait_time += tv.tv_sec;
-            if (tv.tv_usec != 0) wait_time++;
+            wait_time = time(NULL) - start_time;
             break;
         case EAGAIN:
             if (wait_time < SSS_CLI_SOCKET_TIMEOUT) {
-- 
1.7.4.4

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to