Only reject file descriptors higher than FD_SETSIZE if we are not using
poll(2) or kqueue(2). Previously we rejected fd's higher than FD_SETSIZE for kevent(2), and larger than sysconf(_SC_OPEN_MAX) for poll(2). However, the check for poll(2) wasn't really needed. open(2) and socket(2) won't return an fd you can't pass to either poll(2) or kevent(2). This fixes a but where gethostbyname() would fail if you had more than 1023 files open in a process. MFC after: 1 week Reviewed by: ume Found by: ps
This commit is contained in:
parent
89f0549d37
commit
5e41bd2cd2
@ -124,10 +124,8 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#define EXT(res) ((res)->_u._ext)
|
||||
|
||||
#ifndef USE_POLL
|
||||
#if !defined(USE_POLL) && !defined(USE_KQUEUE)
|
||||
static const int highestFD = FD_SETSIZE - 1;
|
||||
#else
|
||||
static int highestFD = 0;
|
||||
#endif
|
||||
|
||||
/* Forward. */
|
||||
@ -305,10 +303,6 @@ res_nsend(res_state statp,
|
||||
#endif
|
||||
char abuf[NI_MAXHOST];
|
||||
|
||||
#ifdef USE_POLL
|
||||
highestFD = sysconf(_SC_OPEN_MAX) - 1;
|
||||
#endif
|
||||
|
||||
/* No name servers or res_init() failure */
|
||||
if (statp->nscount == 0 || EXT(statp).ext == NULL) {
|
||||
errno = ESRCH;
|
||||
@ -659,10 +653,12 @@ send_vc(res_state statp,
|
||||
res_nclose(statp);
|
||||
|
||||
statp->_vcsock = _socket(nsap->sa_family, SOCK_STREAM, 0);
|
||||
#if !defined(USE_POLL) && !defined(USE_KQUEUE)
|
||||
if (statp->_vcsock > highestFD) {
|
||||
res_nclose(statp);
|
||||
errno = ENOTSOCK;
|
||||
}
|
||||
#endif
|
||||
if (statp->_vcsock < 0) {
|
||||
switch (errno) {
|
||||
case EPROTONOSUPPORT:
|
||||
@ -837,10 +833,12 @@ send_dg(res_state statp,
|
||||
if (EXT(statp).nssocks[ns] == -1) {
|
||||
EXT(statp).nssocks[ns] = _socket(nsap->sa_family,
|
||||
SOCK_DGRAM, 0);
|
||||
#if !defined(USE_POLL) && !defined(USE_KQUEUE)
|
||||
if (EXT(statp).nssocks[ns] > highestFD) {
|
||||
res_nclose(statp);
|
||||
errno = ENOTSOCK;
|
||||
}
|
||||
#endif
|
||||
if (EXT(statp).nssocks[ns] < 0) {
|
||||
switch (errno) {
|
||||
case EPROTONOSUPPORT:
|
||||
|
Loading…
x
Reference in New Issue
Block a user