mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Test for overflowing platform FD_SET size.
This commit is contained in:
@@ -760,15 +760,13 @@ void set_dbus_listeners(int *maxfdp,
|
|||||||
unsigned int flags = dbus_watch_get_flags(w->watch);
|
unsigned int flags = dbus_watch_get_flags(w->watch);
|
||||||
int fd = dbus_watch_get_unix_fd(w->watch);
|
int fd = dbus_watch_get_unix_fd(w->watch);
|
||||||
|
|
||||||
bump_maxfd(fd, maxfdp);
|
|
||||||
|
|
||||||
if (flags & DBUS_WATCH_READABLE)
|
if (flags & DBUS_WATCH_READABLE)
|
||||||
FD_SET(fd, rset);
|
bump_maxfd(rset, fd, maxfdp);
|
||||||
|
|
||||||
if (flags & DBUS_WATCH_WRITABLE)
|
if (flags & DBUS_WATCH_WRITABLE)
|
||||||
FD_SET(fd, wset);
|
bump_maxfd(wset, fd, maxfdp);
|
||||||
|
|
||||||
FD_SET(fd, eset);
|
bump_maxfd(eset, fd, maxfdp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -902,48 +902,32 @@ int main (int argc, char **argv)
|
|||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
if (daemon->dhcp || daemon->relay4)
|
if (daemon->dhcp || daemon->relay4)
|
||||||
{
|
{
|
||||||
FD_SET(daemon->dhcpfd, &rset);
|
bump_maxfd(&rset, daemon->dhcpfd, &maxfd);
|
||||||
bump_maxfd(daemon->dhcpfd, &maxfd);
|
|
||||||
if (daemon->pxefd != -1)
|
if (daemon->pxefd != -1)
|
||||||
{
|
bump_maxfd(&rset, daemon->pxefd, &maxfd);
|
||||||
FD_SET(daemon->pxefd, &rset);
|
|
||||||
bump_maxfd(daemon->pxefd, &maxfd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (daemon->doing_dhcp6 || daemon->relay6)
|
if (daemon->doing_dhcp6 || daemon->relay6)
|
||||||
{
|
bump_maxfd(&rset, daemon->dhcp6fd, &maxfd);
|
||||||
FD_SET(daemon->dhcp6fd, &rset);
|
|
||||||
bump_maxfd(daemon->dhcp6fd, &maxfd);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (daemon->doing_ra)
|
if (daemon->doing_ra)
|
||||||
{
|
bump_maxfd(&rset, daemon->icmp6fd, &maxfd);
|
||||||
FD_SET(daemon->icmp6fd, &rset);
|
|
||||||
bump_maxfd(daemon->icmp6fd, &maxfd);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_INOTIFY
|
#ifdef HAVE_INOTIFY
|
||||||
if (daemon->inotifyfd != -1)
|
if (daemon->inotifyfd != -1)
|
||||||
{
|
bump_maxfd(&rset, daemon->inotifyfd, &maxfd);
|
||||||
FD_SET(daemon->inotifyfd, &rset);
|
|
||||||
bump_maxfd(daemon->inotifyfd, &maxfd);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_LINUX_NETWORK)
|
#if defined(HAVE_LINUX_NETWORK)
|
||||||
FD_SET(daemon->netlinkfd, &rset);
|
bump_maxfd(&rset, daemon->netlinkfd, &maxfd);
|
||||||
bump_maxfd(daemon->netlinkfd, &maxfd);
|
|
||||||
#elif defined(HAVE_BSD_NETWORK)
|
#elif defined(HAVE_BSD_NETWORK)
|
||||||
FD_SET(daemon->routefd, &rset);
|
bump_maxfd(&rset, daemon->routefd, &maxfd);
|
||||||
bump_maxfd(daemon->routefd, &maxfd);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FD_SET(piperead, &rset);
|
bump_maxfd(&rset, piperead, &maxfd);
|
||||||
bump_maxfd(piperead, &maxfd);
|
|
||||||
|
|
||||||
#ifdef HAVE_DHCP
|
#ifdef HAVE_DHCP
|
||||||
# ifdef HAVE_SCRIPT
|
# ifdef HAVE_SCRIPT
|
||||||
@@ -954,10 +938,7 @@ int main (int argc, char **argv)
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (!helper_buf_empty())
|
if (!helper_buf_empty())
|
||||||
{
|
bump_maxfd(&wset, daemon->helperfd, &maxfd);
|
||||||
FD_SET(daemon->helperfd, &wset);
|
|
||||||
bump_maxfd(daemon->helperfd, &maxfd);
|
|
||||||
}
|
|
||||||
# else
|
# else
|
||||||
/* need this for other side-effects */
|
/* need this for other side-effects */
|
||||||
while (do_script_run(now));
|
while (do_script_run(now));
|
||||||
@@ -1482,8 +1463,7 @@ static int set_dns_listeners(time_t now, fd_set *set, int *maxfdp)
|
|||||||
for (transfer = daemon->tftp_trans; transfer; transfer = transfer->next)
|
for (transfer = daemon->tftp_trans; transfer; transfer = transfer->next)
|
||||||
{
|
{
|
||||||
tftp++;
|
tftp++;
|
||||||
FD_SET(transfer->sockfd, set);
|
bump_maxfd(set, transfer->sockfd, maxfdp);
|
||||||
bump_maxfd(transfer->sockfd, maxfdp);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1492,27 +1472,18 @@ static int set_dns_listeners(time_t now, fd_set *set, int *maxfdp)
|
|||||||
get_new_frec(now, &wait, 0);
|
get_new_frec(now, &wait, 0);
|
||||||
|
|
||||||
for (serverfdp = daemon->sfds; serverfdp; serverfdp = serverfdp->next)
|
for (serverfdp = daemon->sfds; serverfdp; serverfdp = serverfdp->next)
|
||||||
{
|
bump_maxfd(set, serverfdp->fd, maxfdp);
|
||||||
FD_SET(serverfdp->fd, set);
|
|
||||||
bump_maxfd(serverfdp->fd, maxfdp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (daemon->port != 0 && !daemon->osport)
|
if (daemon->port != 0 && !daemon->osport)
|
||||||
for (i = 0; i < RANDOM_SOCKS; i++)
|
for (i = 0; i < RANDOM_SOCKS; i++)
|
||||||
if (daemon->randomsocks[i].refcount != 0)
|
if (daemon->randomsocks[i].refcount != 0)
|
||||||
{
|
bump_maxfd(set, daemon->randomsocks[i].fd, maxfdp);
|
||||||
FD_SET(daemon->randomsocks[i].fd, set);
|
|
||||||
bump_maxfd(daemon->randomsocks[i].fd, maxfdp);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (listener = daemon->listeners; listener; listener = listener->next)
|
for (listener = daemon->listeners; listener; listener = listener->next)
|
||||||
{
|
{
|
||||||
/* only listen for queries if we have resources */
|
/* only listen for queries if we have resources */
|
||||||
if (listener->fd != -1 && wait == 0)
|
if (listener->fd != -1 && wait == 0)
|
||||||
{
|
bump_maxfd(set, listener->fd, maxfdp);
|
||||||
FD_SET(listener->fd, set);
|
|
||||||
bump_maxfd(listener->fd, maxfdp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* death of a child goes through the select loop, so
|
/* death of a child goes through the select loop, so
|
||||||
we don't need to explicitly arrange to wake up here */
|
we don't need to explicitly arrange to wake up here */
|
||||||
@@ -1520,17 +1491,13 @@ static int set_dns_listeners(time_t now, fd_set *set, int *maxfdp)
|
|||||||
for (i = 0; i < MAX_PROCS; i++)
|
for (i = 0; i < MAX_PROCS; i++)
|
||||||
if (daemon->tcp_pids[i] == 0)
|
if (daemon->tcp_pids[i] == 0)
|
||||||
{
|
{
|
||||||
FD_SET(listener->tcpfd, set);
|
bump_maxfd(set, listener->tcpfd, maxfdp);
|
||||||
bump_maxfd(listener->tcpfd, maxfdp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_TFTP
|
#ifdef HAVE_TFTP
|
||||||
if (tftp <= daemon->tftp_max && listener->tftpfd != -1)
|
if (tftp <= daemon->tftp_max && listener->tftpfd != -1)
|
||||||
{
|
bump_maxfd(set, listener->tftpfd, maxfdp);
|
||||||
FD_SET(listener->tftpfd, set);
|
|
||||||
bump_maxfd(listener->tftpfd, maxfdp);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1822,10 +1789,7 @@ int icmp_ping(struct in_addr addr)
|
|||||||
|
|
||||||
#ifdef HAVE_DHCP6
|
#ifdef HAVE_DHCP6
|
||||||
if (daemon->doing_ra)
|
if (daemon->doing_ra)
|
||||||
{
|
bump_maxfd(&rset, daemon->icmp6fd, &maxfd);
|
||||||
FD_SET(daemon->icmp6fd, &rset);
|
|
||||||
bump_maxfd(daemon->icmp6fd, &maxfd);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rc = select(maxfd+1, &rset, &wset, NULL, &tv);
|
rc = select(maxfd+1, &rset, &wset, NULL, &tv);
|
||||||
|
|||||||
@@ -1191,7 +1191,7 @@ int memcmp_masked(unsigned char *a, unsigned char *b, int len,
|
|||||||
unsigned int mask);
|
unsigned int mask);
|
||||||
int expand_buf(struct iovec *iov, size_t size);
|
int expand_buf(struct iovec *iov, size_t size);
|
||||||
char *print_mac(char *buff, unsigned char *mac, int len);
|
char *print_mac(char *buff, unsigned char *mac, int len);
|
||||||
void bump_maxfd(int fd, int *max);
|
void bump_maxfd(fd_set *set, int fd, int *max);
|
||||||
int read_write(int fd, unsigned char *packet, int size, int rw);
|
int read_write(int fd, unsigned char *packet, int size, int rw);
|
||||||
|
|
||||||
int wildcard_match(const char* wildcard, const char* match);
|
int wildcard_match(const char* wildcard, const char* match);
|
||||||
|
|||||||
@@ -424,10 +424,7 @@ void my_syslog(int priority, const char *format, ...)
|
|||||||
void set_log_writer(fd_set *set, int *maxfdp)
|
void set_log_writer(fd_set *set, int *maxfdp)
|
||||||
{
|
{
|
||||||
if (entries && log_fd != -1 && connection_good)
|
if (entries && log_fd != -1 && connection_good)
|
||||||
{
|
bump_maxfd(set, log_fd, maxfdp);
|
||||||
FD_SET(log_fd, set);
|
|
||||||
bump_maxfd(log_fd, maxfdp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_log_writer(fd_set *set)
|
void check_log_writer(fd_set *set)
|
||||||
|
|||||||
19
src/util.c
19
src/util.c
@@ -570,10 +570,23 @@ char *print_mac(char *buff, unsigned char *mac, int len)
|
|||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bump_maxfd(int fd, int *max)
|
void bump_maxfd(fd_set *set, int fd, int *max)
|
||||||
{
|
{
|
||||||
if (fd > *max)
|
#ifdef FD_SETSIZE
|
||||||
*max = fd;
|
if (fd >= FD_SETSIZE)
|
||||||
|
{
|
||||||
|
static int logged = 0;
|
||||||
|
if (!logged)
|
||||||
|
my_syslog(LOG_ERR, _("File descriptor overflows FS_SET"));
|
||||||
|
logged = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
FD_SET(fd, set);
|
||||||
|
if (fd > *max)
|
||||||
|
*max = fd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rc is return from sendto and friends.
|
/* rc is return from sendto and friends.
|
||||||
|
|||||||
Reference in New Issue
Block a user