The Samba-Bugzilla – Attachment 6249 Details for
Bug 7949
DoS in Winbind and smbd with many file descriptors open; CVE-2011-0719
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for 3.4.x.
samba-3-4-fd_set.patch (text/plain), 20.86 KB, created by
Jeremy Allison
on 2011-02-15 19:16:59 UTC
(
hide
)
Description:
Patch for 3.4.x.
Filename:
MIME Type:
Creator:
Jeremy Allison
Created:
2011-02-15 19:16:59 UTC
Size:
20.86 KB
patch
obsolete
>diff --git a/lib/tdb/common/freelist.c b/lib/tdb/common/freelist.c >index 2f2a4c3..f485bd5 100644 >--- a/lib/tdb/common/freelist.c >+++ b/lib/tdb/common/freelist.c >@@ -27,12 +27,6 @@ > > #include "tdb_private.h" > >-/* 'right' merges can involve O(n^2) cost when combined with a >- traverse, so they are disabled until we find a way to do them in >- O(1) time >-*/ >-#define USE_RIGHT_MERGES 0 >- > /* read a freelist record and check for simple errors */ > int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct list_struct *rec) > { >@@ -62,8 +56,11 @@ int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct list_struct > } > > >-#if USE_RIGHT_MERGES > /* Remove an element from the freelist. Must have alloc lock. */ >+/* 'right' merges can involve O(n^2) cost when combined with a >+ traverse, so they are disabled by default, but available as a >+ tuning parameter, until we find a way to do them in O(1) time >+*/ > static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_t next) > { > tdb_off_t last_ptr, i; >@@ -81,8 +78,6 @@ static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_ > TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%d\n", off)); > return TDB_ERRCODE(TDB_ERR_CORRUPT, -1); > } >-#endif >- > > /* update a record tailer (must hold allocation lock) */ > static int update_tailer(struct tdb_context *tdb, tdb_off_t offset, >@@ -110,32 +105,33 @@ int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec) > goto fail; > } > >-#if USE_RIGHT_MERGES >- /* Look right first (I'm an Australian, dammit) */ >- if (offset + sizeof(*rec) + rec->rec_len + sizeof(*rec) <= tdb->map_size) { >- tdb_off_t right = offset + sizeof(*rec) + rec->rec_len; >- struct list_struct r; >+ if (tdb->freelist_merge_right) { >+ /* Look right first (I'm an Australian, dammit) */ >+ if (offset + sizeof(*rec) + rec->rec_len + sizeof(*rec) <= tdb->map_size) { >+ tdb_off_t right = offset + sizeof(*rec) + rec->rec_len; >+ struct list_struct r; > >- if (tdb->methods->tdb_read(tdb, right, &r, sizeof(r), DOCONV()) == -1) { >- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right read failed at %u\n", right)); >- goto left; >- } >- >- /* If it's free, expand to include it. */ >- if (r.magic == TDB_FREE_MAGIC) { >- if (remove_from_freelist(tdb, right, r.next) == -1) { >- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right free failed at %u\n", right)); >+ if (tdb->methods->tdb_read(tdb, right, &r, sizeof(r), DOCONV()) == -1) { >+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right read failed at %u\n", right)); > goto left; > } >- rec->rec_len += sizeof(r) + r.rec_len; >- if (update_tailer(tdb, offset, rec) == -1) { >- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed at %u\n", offset)); >- goto fail; >+ >+ /* If it's free, expand to include it. */ >+ if (r.magic == TDB_FREE_MAGIC) { >+ if (remove_from_freelist(tdb, right, r.next) == -1) { >+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right free failed at %u\n", right)); >+ goto left; >+ } >+ rec->rec_len += sizeof(r) + r.rec_len; >+ if (update_tailer(tdb, offset, rec) == -1) { >+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed at %u\n", offset)); >+ goto fail; >+ } > } > } > } >+ > left: >-#endif > > /* Look left */ > if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->header.hash_size)) { >diff --git a/lib/tdb/common/io.c b/lib/tdb/common/io.c >index 661f761..2e53296 100644 >--- a/lib/tdb/common/io.c >+++ b/lib/tdb/common/io.c >@@ -306,10 +306,11 @@ int tdb_expand(struct tdb_context *tdb, tdb_off_t size) > /* must know about any previous expansions by another process */ > tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1); > >- /* always make room for at least 100 more records, and at >- least 25% more space. Round the database up to a multiple >+ /* always make room for at least tdb->record_number_expansion_factor more records, and at >+ least tdb->min_filesize_expansion_factor% more space. Round the database up to a multiple > of the page size */ >- new_size = MAX(tdb->map_size + size*100, tdb->map_size * 1.25); >+ new_size = MAX(tdb->map_size + size*tdb->record_number_expansion_factor, >+ tdb->map_size * tdb->min_filesize_expansion_factor); > size = TDB_ALIGN(new_size, tdb->page_size) - tdb->map_size; > > if (!(tdb->flags & TDB_INTERNAL)) >diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c >index 49b8e85..656298c 100644 >--- a/lib/tdb/common/open.c >+++ b/lib/tdb/common/open.c >@@ -180,6 +180,9 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, > } > > tdb->max_dead_records = (tdb_flags & TDB_VOLATILE) ? 5 : 0; >+ tdb->record_number_expansion_factor = TDB_DEFAULT_RECORD_NUMBER_EXPANSION_FACTOR; >+ tdb->min_filesize_expansion_factor = TDB_DEFAULT_MIN_FILESIZE_EXPANSION_FACTOR; >+ tdb->freelist_merge_right = false; > > if ((open_flags & O_ACCMODE) == O_WRONLY) { > TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't open tdb %s write-only\n", >diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c >index b59bb15..bb810a4 100644 >--- a/lib/tdb/common/tdb.c >+++ b/lib/tdb/common/tdb.c >@@ -894,3 +894,38 @@ int tdb_repack(struct tdb_context *tdb) > > return 0; > } >+ >+int tdb_set_tuning_parameter(struct tdb_context *tdb, >+ enum TDB_TUNE_PARAMETER tuning_param, ...) >+{ >+ va_list ap; >+ >+ va_start(ap, tuning_param); >+ >+ switch ((int)tuning_param) { >+ case TDB_TUNE_RECORD_NUMBER_EXPANSION_FACTOR: >+ { >+ unsigned int record_number_expansion_factor = (unsigned int)va_arg(ap, int); >+ if (record_number_expansion_factor == 0) { >+ record_number_expansion_factor = TDB_DEFAULT_RECORD_NUMBER_EXPANSION_FACTOR; >+ } >+ tdb->record_number_expansion_factor = record_number_expansion_factor; >+ return 0; >+ } >+ case TDB_TUNE_MIN_FILESIZE_EXPANSION_FACTOR: >+ { >+ double min_filesize_expansion_factor = va_arg(ap, double); >+ if (min_filesize_expansion_factor == 0.0) { >+ min_filesize_expansion_factor = TDB_DEFAULT_MIN_FILESIZE_EXPANSION_FACTOR; >+ } >+ tdb->min_filesize_expansion_factor = min_filesize_expansion_factor; >+ return 0; >+ } >+ case TDB_TUNE_FREELIST_MERGE_RIGHT: >+ { >+ tdb->freelist_merge_right = (bool)va_arg(ap, int); >+ return 0; >+ } >+ } >+ return -1; >+} >diff --git a/lib/tdb/common/tdb_private.h b/lib/tdb/common/tdb_private.h >index ffac89f..0fe6096 100644 >--- a/lib/tdb/common/tdb_private.h >+++ b/lib/tdb/common/tdb_private.h >@@ -63,6 +63,9 @@ typedef uint32_t tdb_off_t; > #define TDB_PAD_BYTE 0x42 > #define TDB_PAD_U32 0x42424242 > >+#define TDB_DEFAULT_RECORD_NUMBER_EXPANSION_FACTOR 100 >+#define TDB_DEFAULT_MIN_FILESIZE_EXPANSION_FACTOR 1.25 >+ > /* NB assumes there is a local variable called "tdb" that is the > * current context, also takes doubly-parenthesized print-style > * argument. */ >@@ -168,6 +171,9 @@ struct tdb_context { > int max_dead_records; > bool have_transaction_lock; > volatile sig_atomic_t *interrupt_sig_ptr; >+ unsigned int record_number_expansion_factor; >+ double min_filesize_expansion_factor; >+ bool freelist_merge_right; > }; > > >diff --git a/lib/tdb/include/tdb.h b/lib/tdb/include/tdb.h >index 94b5e36..8f3feba 100644 >--- a/lib/tdb/include/tdb.h >+++ b/lib/tdb/include/tdb.h >@@ -77,6 +77,11 @@ typedef struct TDB_DATA { > #endif > #endif > >+/* possible tdb tuning constants. */ >+enum TDB_TUNE_PARAMETER { TDB_TUNE_RECORD_NUMBER_EXPANSION_FACTOR = 1, >+ TDB_TUNE_MIN_FILESIZE_EXPANSION_FACTOR, >+ TDB_TUNE_FREELIST_MERGE_RIGHT}; >+ > /* this is the context structure that is returned from a db open */ > typedef struct tdb_context TDB_CONTEXT; > >@@ -140,6 +145,7 @@ void tdb_add_flags(struct tdb_context *tdb, unsigned flag); > void tdb_remove_flags(struct tdb_context *tdb, unsigned flag); > void tdb_enable_seqnum(struct tdb_context *tdb); > void tdb_increment_seqnum_nonblock(struct tdb_context *tdb); >+int tdb_set_tuning_parameter(struct tdb_context *tdb, enum TDB_TUNE_PARAMETER tuning_param, ...); > > /* Low level locking functions: use with care */ > int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key); >diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c >index d974189..890e031 100644 >--- a/lib/tevent/tevent_select.c >+++ b/lib/tevent/tevent_select.c >@@ -111,6 +111,11 @@ static struct tevent_fd *select_event_add_fd(struct tevent_context *ev, TALLOC_C > struct select_event_context); > struct tevent_fd *fde; > >+ if (fd < 0 || fd >= FD_SETSIZE) { >+ errno = EBADF; >+ return NULL; >+ } >+ > fde = tevent_common_add_fd(ev, mem_ctx, fd, flags, > handler, private_data, > handler_name, location); >@@ -143,6 +148,11 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru > > /* setup any fd events */ > for (fde = select_ev->ev->fd_events; fde; fde = fde->next) { >+ if (fde->fd < 0 || fde->fd >= FD_SETSIZE) { >+ errno = EBADF; >+ return -1; >+ } >+ > if (fde->flags & TEVENT_FD_READ) { > FD_SET(fde->fd, &r_fds); > } >diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c >index c3f8b36..d4a00cc 100644 >--- a/lib/tevent/tevent_standard.c >+++ b/lib/tevent/tevent_standard.c >@@ -457,6 +457,11 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva > > /* setup any fd events */ > for (fde = std_ev->ev->fd_events; fde; fde = fde->next) { >+ if (fde->fd < 0 || fde->fd >= FD_SETSIZE) { >+ std_ev->exit_code = EBADF; >+ return -1; >+ } >+ > if (fde->flags & TEVENT_FD_READ) { > FD_SET(fde->fd, &r_fds); > } >diff --git a/nsswitch/wb_common.c b/nsswitch/wb_common.c >index d0dfcb8..75ce585 100644 >--- a/nsswitch/wb_common.c >+++ b/nsswitch/wb_common.c >@@ -240,6 +240,12 @@ static int winbind_named_pipe_sock(const char *dir) > > switch (errno) { > case EINPROGRESS: >+ >+ if (fd < 0 || fd >= FD_SETSIZE) { >+ errno = EBADF; >+ goto error_out; >+ } >+ > FD_ZERO(&w_fds); > FD_SET(fd, &w_fds); > tv.tv_sec = CONNECT_TIMEOUT - wait_time; >@@ -384,6 +390,12 @@ int winbind_write_sock(void *buffer, int count, int recursing, int need_priv) > struct timeval tv; > fd_set r_fds; > >+ if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) { >+ errno = EBADF; >+ winbind_close_sock(); >+ return -1; >+ } >+ > /* Catch pipe close on other end by checking if a read() > call would not block by calling select(). */ > >@@ -444,6 +456,11 @@ int winbind_read_sock(void *buffer, int count) > struct timeval tv; > fd_set r_fds; > >+ if (winbindd_fd < 0 || winbindd_fd >= FD_SETSIZE) { >+ errno = EBADF; >+ winbind_close_sock(); >+ return -1; >+ } > /* Catch pipe close on other end by checking if a read() > call would not block by calling select(). */ > >diff --git a/source3/client/client.c b/source3/client/client.c >index b706591..1e5e8e1 100644 >--- a/source3/client/client.c >+++ b/source3/client/client.c >@@ -4384,8 +4384,10 @@ static void readline_callback(void) > > again: > >- if (cli->fd == -1) >+ if (cli->fd < 0 || cli->fd >= FD_SETSIZE) { >+ errno = EBADF; > return; >+ } > > FD_ZERO(&fds); > FD_SET(cli->fd,&fds); >diff --git a/source3/client/dnsbrowse.c b/source3/client/dnsbrowse.c >index 5e3a4de..a6b9360 100644 >--- a/source3/client/dnsbrowse.c >+++ b/source3/client/dnsbrowse.c >@@ -81,6 +81,11 @@ static void do_smb_resolve(struct mdns_smbsrv_result *browsesrv) > TALLOC_FREE(fdset); > } > >+ if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) { >+ errno = EBADF; >+ break; >+ } >+ > fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask); > fdset = TALLOC_ZERO(ctx, fdsetsz); > FD_SET(mdnsfd, fdset); >@@ -181,6 +186,12 @@ int do_smb_browse(void) > TALLOC_FREE(fdset); > } > >+ if (mdnsfd < 0 || mdnsfd >= FD_SETSIZE) { >+ errno = EBADF; >+ TALLOC_FREE(ctx); >+ return 1; >+ } >+ > fdsetsz = howmany(mdnsfd + 1, NFDBITS) * sizeof(fd_mask); > fdset = TALLOC_ZERO(ctx, fdsetsz); > FD_SET(mdnsfd, fdset); >diff --git a/source3/lib/events.c b/source3/lib/events.c >index 90d86c6..3c83f81 100644 >--- a/source3/lib/events.c >+++ b/source3/lib/events.c >@@ -55,6 +55,14 @@ bool event_add_to_select_args(struct tevent_context *ev, > bool ret = false; > > for (fde = ev->fd_events; fde; fde = fde->next) { >+ if (fde->fd < 0 || fde->fd >= FD_SETSIZE) { >+ /* We ignore here, as it shouldn't be >+ possible to add an invalid fde->fd >+ but we don't want FD_SET to see an >+ invalid fd. */ >+ continue; >+ } >+ > if (fde->flags & EVENT_FD_READ) { > FD_SET(fde->fd, read_fds); > ret = true; >diff --git a/source3/lib/packet.c b/source3/lib/packet.c >index ef28bf9..c14d1e5 100644 >--- a/source3/lib/packet.c >+++ b/source3/lib/packet.c >@@ -106,6 +106,11 @@ NTSTATUS packet_fd_read_sync(struct packet_context *ctx) > int res; > fd_set r_fds; > >+ if (ctx->fd < 0 || ctx->fd >= FD_SETSIZE) { >+ errno = EBADF; >+ return map_nt_error_from_unix(errno); >+ } >+ > FD_ZERO(&r_fds); > FD_SET(ctx->fd, &r_fds); > >diff --git a/source3/lib/readline.c b/source3/lib/readline.c >index 34867aa..70a82f2 100644 >--- a/source3/lib/readline.c >+++ b/source3/lib/readline.c >@@ -91,6 +91,11 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) > timeout.tv_sec = 5; > timeout.tv_usec = 0; > >+ if (fd < 0 || fd >= FD_SETSIZE) { >+ errno = EBADF; >+ break; >+ } >+ > FD_ZERO(&fds); > FD_SET(fd,&fds); > >diff --git a/source3/lib/select.c b/source3/lib/select.c >index b5443ff..5aae2dc 100644 >--- a/source3/lib/select.c >+++ b/source3/lib/select.c >@@ -101,6 +101,11 @@ int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, s > readfds2 = &readfds_buf; > FD_ZERO(readfds2); > } >+ if (select_pipe[0] < 0 || select_pipe[0] >= FD_SETSIZE) { >+ errno = EBADF; >+ return -1; >+ } >+ > FD_SET(select_pipe[0], readfds2); > > errno = 0; >diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c >index da79aca..238daf4 100644 >--- a/source3/lib/util_sock.c >+++ b/source3/lib/util_sock.c >@@ -560,6 +560,11 @@ NTSTATUS read_fd_with_timeout(int fd, char *buf, > timeout.tv_usec = (long)(1000 * (time_out % 1000)); > > for (nread=0; nread < mincnt; ) { >+ if (fd < 0 || fd >= FD_SETSIZE) { >+ errno = EBADF; >+ return map_nt_error_from_unix(EBADF); >+ } >+ > FD_ZERO(&fds); > FD_SET(fd,&fds); > >@@ -1294,7 +1299,7 @@ bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs, > > for (i=0; i<num_addrs; i++) { > sockets[i] = socket(addrs[i].ss_family, SOCK_STREAM, 0); >- if (sockets[i] < 0) >+ if (sockets[i] < 0 || sockets[i] >= FD_SETSIZE) > goto done; > set_blocking(sockets[i], false); > } >@@ -1343,8 +1348,10 @@ bool open_any_socket_out(struct sockaddr_storage *addrs, int num_addrs, > FD_ZERO(&r_fds); > > for (i=0; i<num_addrs; i++) { >- if (sockets[i] == -1) >+ if (sockets[i] < 0 || sockets[i] >= FD_SETSIZE) { >+ /* This cannot happen - ignore if so. */ > continue; >+ } > FD_SET(sockets[i], &wr_fds); > FD_SET(sockets[i], &r_fds); > if (sockets[i]>maxfd) >diff --git a/source3/lib/wbclient.c b/source3/lib/wbclient.c >index 3cf992c..9cb250d 100644 >--- a/source3/lib/wbclient.c >+++ b/source3/lib/wbclient.c >@@ -120,7 +120,7 @@ static bool winbind_closed_fd(int fd) > struct timeval tv; > fd_set r_fds; > >- if (fd == -1) { >+ if (fd == -1 || fd >= FD_SETSIZE) { > return true; > } > >@@ -222,6 +222,13 @@ static struct tevent_req *wb_connect_send(TALLOC_CTX *mem_ctx, > wbc_err = map_wbc_err_from_errno(errno); > goto post_status; > } >+ if (wb_ctx->fd >= FD_SETSIZE) { >+ close(wb_ctx->fd); >+ wb_ctx->fd = -1; >+ errno = EBADF; >+ wbc_err = map_wbc_err_from_errno(errno); >+ goto post_status; >+ } > > subreq = async_connect_send(mem_ctx, ev, wb_ctx->fd, > (struct sockaddr *)&sunaddr, >diff --git a/source3/libaddns/dnssock.c b/source3/libaddns/dnssock.c >index 7c8bd41..bf11fea 100644 >--- a/source3/libaddns/dnssock.c >+++ b/source3/libaddns/dnssock.c >@@ -219,6 +219,11 @@ static DNS_ERROR read_all(int fd, uint8 *data, size_t len) > ssize_t ret; > int fd_ready; > >+ if (fd < 0 || fd >= FD_SETSIZE) { >+ /* read timeout */ >+ return ERROR_DNS_SOCKET_ERROR; >+ } >+ > FD_ZERO( &rfds ); > FD_SET( fd, &rfds ); > >diff --git a/source3/libads/cldap.c b/source3/libads/cldap.c >index ae087d9..ac4e2cb 100644 >--- a/source3/libads/cldap.c >+++ b/source3/libads/cldap.c >@@ -134,6 +134,11 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx, > return -1; > } > >+ if (sock < 0 || sock >= FD_SETSIZE) { >+ errno = EBADF; >+ return -1; >+ } >+ > FD_ZERO(&r_fds); > FD_SET(sock, &r_fds); > >diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c >index 1206d9d..8230c5a 100644 >--- a/source3/libsmb/nmblib.c >+++ b/source3/libsmb/nmblib.c >@@ -1089,6 +1089,11 @@ struct packet_struct *receive_packet(int fd,enum packet_type type,int t) > struct timeval timeout; > int ret; > >+ if (fd < 0 || fd >= FD_SETSIZE) { >+ errno = EBADF; >+ return NULL; >+ } >+ > FD_ZERO(&fds); > FD_SET(fd,&fds); > timeout.tv_sec = t/1000; >diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c >index f69845b..1c570ea 100644 >--- a/source3/nmbd/nmbd_packets.c >+++ b/source3/nmbd/nmbd_packets.c >@@ -1683,7 +1683,7 @@ static bool create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_n > for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) > count++; > >- if((count*2) + 2 > FD_SETSIZE) { >+ if((count*2) + 2 >= FD_SETSIZE) { > DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \ > only use %d.\n", (count*2) + 2, FD_SETSIZE)); > SAFE_FREE(pset); >@@ -1699,24 +1699,44 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); > FD_ZERO(pset); > > /* Add in the broadcast socket on 137. */ >+ if (ClientNMB < 0 || ClientNMB >= FD_SETSIZE) { >+ errno = EBADF; >+ SAFE_FREE(pset); >+ return True; >+ } >+ > FD_SET(ClientNMB,pset); > sock_array[num++] = ClientNMB; > *maxfd = MAX( *maxfd, ClientNMB); > > /* Add in the 137 sockets on all the interfaces. */ > for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { >+ if (subrec->nmb_sock < 0 || subrec->nmb_sock >= FD_SETSIZE) { >+ /* We have to ignore sockets outside FD_SETSIZE. */ >+ continue; >+ } > FD_SET(subrec->nmb_sock,pset); > sock_array[num++] = subrec->nmb_sock; > *maxfd = MAX( *maxfd, subrec->nmb_sock); > } > > /* Add in the broadcast socket on 138. */ >+ if (ClientDGRAM < 0 || ClientDGRAM >= FD_SETSIZE) { >+ errno = EBADF; >+ SAFE_FREE(pset); >+ return True; >+ } >+ > FD_SET(ClientDGRAM,pset); > sock_array[num++] = ClientDGRAM; > *maxfd = MAX( *maxfd, ClientDGRAM); > > /* Add in the 138 sockets on all the interfaces. */ > for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { >+ if (subrec->dgram_sock < 0 || subrec->dgram_sock >= FD_SETSIZE) { >+ /* We have to ignore sockets outside FD_SETSIZE. */ >+ continue; >+ } > FD_SET(subrec->dgram_sock,pset); > sock_array[num++] = subrec->dgram_sock; > *maxfd = MAX( *maxfd, subrec->dgram_sock); >@@ -1767,7 +1787,7 @@ bool listen_for_packets(bool run_election) > > #ifndef SYNC_DNS > dns_fd = asyncdns_fd(); >- if (dns_fd != -1) { >+ if (dns_fd >= 0 && dns_fd < FD_SETSIZE) { > FD_SET(dns_fd, &r_fds); > maxfd = MAX( maxfd, dns_fd); > } >diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c >index 39a2640..a3ed657 100644 >--- a/source3/utils/smbfilter.c >+++ b/source3/utils/smbfilter.c >@@ -170,8 +170,8 @@ static void filter_child(int c, struct sockaddr_storage *dest_ss) > int num; > > FD_ZERO(&fds); >- if (s != -1) FD_SET(s, &fds); >- if (c != -1) FD_SET(c, &fds); >+ if (s >= 0 && s < FD_SETSIZE) FD_SET(s, &fds); >+ if (c >= 0 && c < FD_SETSIZE) FD_SET(c, &fds); > > num = sys_select_intr(MAX(s+1, c+1),&fds,NULL,NULL,NULL); > if (num <= 0) continue; >@@ -243,6 +243,10 @@ static void start_filter(char *desthost) > struct sockaddr_storage ss; > socklen_t in_addrlen = sizeof(ss); > >+ if (s < 0 || s >= FD_SETSIZE) { >+ break; >+ } >+ > FD_ZERO(&fds); > FD_SET(s, &fds); > >diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c >index 0443ebf..b72d42b 100644 >--- a/source3/winbindd/winbindd.c >+++ b/source3/winbindd/winbindd.c >@@ -1064,6 +1064,12 @@ static void process_loop(void) > } > > for (ev = fd_events; ev; ev = ev->next) { >+ if (ev->fd < 0 || ev->fd >= FD_SETSIZE) { >+ /* Ignore here - event_add_to_select_args >+ should make this impossible. */ >+ continue; >+ } >+ > if (ev->flags & EVENT_FD_READ) { > FD_SET(ev->fd, &r_fds); > maxfd = MAX(ev->fd, maxfd); >diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c >index 141ceb1..7da3c82 100644 >--- a/source3/winbindd/winbindd_cache.c >+++ b/source3/winbindd/winbindd_cache.c >@@ -2547,6 +2547,15 @@ bool init_wcache(void) > return false; > } > >+ tdb_set_tuning_parameter(wcache->tdb, >+ TDB_TUNE_RECORD_NUMBER_EXPANSION_FACTOR, >+ 2); >+ tdb_set_tuning_parameter(wcache->tdb, >+ TDB_TUNE_MIN_FILESIZE_EXPANSION_FACTOR, >+ 1.0); >+ tdb_set_tuning_parameter(wcache->tdb, >+ TDB_TUNE_FREELIST_MERGE_RIGHT, >+ 1); > return true; > } > >diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c >index 72e5607..3eef3d3 100644 >--- a/source3/winbindd/winbindd_dual.c >+++ b/source3/winbindd/winbindd_dual.c >@@ -1403,6 +1403,13 @@ static bool fork_domain_child(struct winbindd_child *child) > > FD_ZERO(&r_fds); > FD_ZERO(&w_fds); >+ >+ if (state.sock < 0 || state.sock >= FD_SETSIZE) { >+ TALLOC_FREE(frame); >+ perror("EBADF"); >+ _exit(1); >+ } >+ > FD_SET(state.sock, &r_fds); > maxfd = state.sock; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 7949
:
6248
|
6249
|
6252
|
6253
|
6254
|
6255
|
6256
|
6257
|
6262
|
6264
|
6265
|
6266