1
0
mirror of https://github.com/Yubico/yubico-pam.git synced 2025-02-08 03:54:18 +01:00

Close file descriptors in case fdopen() fails

This makes sure that file descriptors will be closed, even if the
fdopen() call failes, which was overlooked in some cases beforehand.
Should be not an issue in the real world, but let's be as clean as
possible.
This commit is contained in:
Karol Babioch 2018-05-22 17:22:02 +02:00
parent b240534c46
commit 6be87e75af
3 changed files with 5 additions and 1 deletions

View File

@ -833,6 +833,8 @@ parse_cfg (int flags, int argc, const char **argv, struct cfg *cfg)
if (file)
{
cfg->debug_file = file;
} else {
close(fd);
}
}
}

1
util.c
View File

@ -203,6 +203,7 @@ int generate_random(void *buf, int len)
u = fdopen(fd, "r");
if (!u) {
close(fd);
return -1;
}

View File

@ -258,6 +258,7 @@ do_add_hmac_chalresp(YK_KEY *yk, uint8_t slot, bool verbose, char *output_dir, u
f = fdopen (fd, "w");
if (! f) {
fprintf (stderr, "fdopen: %s\n", strerror (errno));
close(fd);
goto out;
}