Skip to content

Commit

Permalink
Add "e" flag to fopen() calls
Browse files Browse the repository at this point in the history
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()
(Yubico#136).
  • Loading branch information
kbabioch committed Apr 6, 2018
1 parent 19b6b36 commit 2c5d4d4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pam_yubico.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion ykpamcfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2c5d4d4

Please sign in to comment.