summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-11-30 15:18:08 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-12-15 23:36:22 +0100
commitd581c9d284e7c635b0379d57e95cb32e682f0f02 (patch)
tree23d275c3a99c61305b6c5428e81b5926b92a03f2 /lib
parent3b56f64923a71a90734c5167d549e4eb14002d18 (diff)
downloadsamba-d581c9d284e7c635b0379d57e95cb32e682f0f02.tar.gz
samba-d581c9d284e7c635b0379d57e95cb32e682f0f02.tar.bz2
samba-d581c9d284e7c635b0379d57e95cb32e682f0f02.zip
genrand: use set_close_on_exec()
this prevents a fd leak to child processes
Diffstat (limited to 'lib')
-rw-r--r--lib/util/genrand.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/util/genrand.c b/lib/util/genrand.c
index 7fe55f345e..b8d3c78fa1 100644
--- a/lib/util/genrand.c
+++ b/lib/util/genrand.c
@@ -172,6 +172,9 @@ static int do_reseed(bool use_fd, int fd)
if (use_fd) {
if (fd == -1) {
fd = open( "/dev/urandom", O_RDONLY,0);
+ if (fd != -1) {
+ set_close_on_exec(fd);
+ }
}
if (fd != -1
&& (read(fd, seed_inbuf, sizeof(seed_inbuf)) == sizeof(seed_inbuf))) {
@@ -232,6 +235,9 @@ _PUBLIC_ void generate_random_buffer(uint8_t *out, int len)
if (bytes_since_reseed < 40) {
if (urand_fd == -1) {
urand_fd = open( "/dev/urandom", O_RDONLY,0);
+ if (urand_fd != -1) {
+ set_close_on_exec(urand_fd);
+ }
}
if(urand_fd != -1 && (read(urand_fd, out, len) == len)) {
return;
@@ -269,6 +275,9 @@ _PUBLIC_ void generate_secret_buffer(uint8_t *out, int len)
{
if (urand_fd == -1) {
urand_fd = open( "/dev/urandom", O_RDONLY,0);
+ if (urand_fd != -1) {
+ set_close_on_exec(urand_fd);
+ }
}
if(urand_fd != -1 && (read(urand_fd, out, len) == len)) {
return;