From 2c5d4d4156955c7babb8c75d80fcc2b73d9b3c81 Mon Sep 17 00:00:00 2001 From: Karol Babioch Date: Thu, 5 Apr 2018 14:32:04 +0200 Subject: [PATCH] Add "e" flag to fopen() calls This adds the `e` flag to fopen() calls, making sure the `O_CLOEXEC` flag is used. This makes sure that the file descriptor is being closed and not leaked into child processes. This was an issues previously due to a missing fclose() (#136). --- pam_yubico.c | 2 +- util.c | 2 +- ykpamcfg.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pam_yubico.c b/pam_yubico.c index 15ae7135..6e6afd9c 100644 --- a/pam_yubico.c +++ b/pam_yubico.c @@ -819,7 +819,7 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg) { if(S_ISREG(st.st_mode)) { - file = fopen(filename, "a"); + file = fopen(filename, "ae"); if(file) { cfg->debug_file = file; diff --git a/util.c b/util.c index 8aab9d1f..9b773536 100644 --- a/util.c +++ b/util.c @@ -188,7 +188,7 @@ int generate_random(void *buf, int len) FILE *u; int res; - u = fopen("/dev/urandom", "r"); + u = fopen("/dev/urandom", "re"); if (!u) { return -1; } diff --git a/ykpamcfg.c b/ykpamcfg.c index 16dbb865..cfc4cd01 100644 --- a/ykpamcfg.c +++ b/ykpamcfg.c @@ -237,7 +237,7 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, u umask(077); - f = fopen (fn, "w"); + f = fopen (fn, "we"); if (! f) { fprintf (stderr, "Failed opening '%s' for writing : %s\n", fn, strerror (errno)); goto out;