add CLOEXEC to various DNS related code
Occasionally file descriptors seem to be leaking across execs from DNS related calls. Set close-on-execute for the various sockets / file to prevent file descriptor leakage. Change-Id: I4724b47bc7236f40c29518a6075598a9bba48b0a
This commit is contained in:
@@ -611,7 +611,7 @@ net_mask(in) /* XXX - should really use system's version of this */
|
||||
static int
|
||||
real_randomid(u_int *random_value) {
|
||||
/* open the nonblocking random device, returning -1 on failure */
|
||||
int random_device = open("/dev/urandom", O_RDONLY);
|
||||
int random_device = open("/dev/urandom", O_RDONLY | O_CLOEXEC);
|
||||
if (random_device < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -779,7 +779,7 @@ send_vc(res_state statp,
|
||||
if (statp->_vcsock >= 0)
|
||||
res_nclose(statp);
|
||||
|
||||
statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);
|
||||
statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
if (statp->_vcsock > highestFD) {
|
||||
res_nclose(statp);
|
||||
errno = ENOTSOCK;
|
||||
@@ -1062,7 +1062,7 @@ send_dg(res_state statp,
|
||||
nsap = get_nsaddr(statp, (size_t)ns);
|
||||
nsaplen = get_salen(nsap);
|
||||
if (EXT(statp).nssocks[ns] == -1) {
|
||||
EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0);
|
||||
EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (EXT(statp).nssocks[ns] > highestFD) {
|
||||
res_nclose(statp);
|
||||
errno = ENOTSOCK;
|
||||
|
||||
Reference in New Issue
Block a user