Fix bug #8972 - Directory group write permission bit is set if unix extensions are...
[samba.git] / nsswitch / wb_common.c
index d0dfcb8bbfb67326d82f2736b8110b3a9baf8688..def41d5cea05b2e68dddf9d03724aa98c01bd108 100644 (file)
@@ -61,6 +61,9 @@ static void init_response(struct winbindd_response *response)
 
 /* Close established socket */
 
+#if HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR
+__attribute__((destructor))
+#endif
 void winbind_close_sock(void)
 {
        if (winbindd_fd != -1) {
@@ -241,6 +244,10 @@ static int winbind_named_pipe_sock(const char *dir)
                switch (errno) {
                        case EINPROGRESS:
                                FD_ZERO(&w_fds);
+                               if (fd < 0 || fd >= FD_SETSIZE) {
+                                       errno = EBADF;
+                                       goto error_out;
+                               }
                                FD_SET(fd, &w_fds);
                                tv.tv_sec = CONNECT_TIMEOUT - wait_time;
                                tv.tv_usec = 0;
@@ -388,6 +395,11 @@ int winbind_write_sock(void *buffer, int count, int recursing, int need_priv)
                   call would not block by calling select(). */
 
                FD_ZERO(&r_fds);
+               if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) {
+                       errno = EBADF;
+                       winbind_close_sock();
+                       return -1;
+               }
                FD_SET(winbindd_fd, &r_fds);
                ZERO_STRUCT(tv);
 
@@ -448,6 +460,11 @@ int winbind_read_sock(void *buffer, int count)
                   call would not block by calling select(). */
 
                FD_ZERO(&r_fds);
+               if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) {
+                       errno = EBADF;
+                       winbind_close_sock();
+                       return -1;
+               }
                FD_SET(winbindd_fd, &r_fds);
                ZERO_STRUCT(tv);
                /* Wait for 5 seconds for a reply. May need to parameterise this... */