diff options
author | Benny Baumann <BenBE@geshi.org> | 2023-12-11 13:43:30 +0100 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2023-12-19 12:22:59 +0000 |
commit | ebc35c605beca9020bb743134575fdc558dfdaf5 (patch) | |
tree | bd4f1a518cd1dbd449d43bfa4dcabb6d91c63556 /modules/pam_timestamp | |
parent | 0a9912e5f7810dffeecad0131b1f0c038457bfe5 (diff) | |
download | pam-ebc35c605beca9020bb743134575fdc558dfdaf5.tar.gz pam-ebc35c605beca9020bb743134575fdc558dfdaf5.tar.bz2 pam-ebc35c605beca9020bb743134575fdc558dfdaf5.zip |
pam_timestamp: allocate memory before opening /dev/urandom
It's handy to have the memory allocated before trying several methods
of obtaining randomness that are going to be introduced by subsequent
commits.
* modules/pam_timestamp/hmac_openssl_wrapper.c (generate_key):
Allocate memory before trying to open /dev/urandom.
Diffstat (limited to 'modules/pam_timestamp')
-rw-r--r-- | modules/pam_timestamp/hmac_openssl_wrapper.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/modules/pam_timestamp/hmac_openssl_wrapper.c b/modules/pam_timestamp/hmac_openssl_wrapper.c index b2aeda21..2f015c6a 100644 --- a/modules/pam_timestamp/hmac_openssl_wrapper.c +++ b/modules/pam_timestamp/hmac_openssl_wrapper.c @@ -85,18 +85,19 @@ generate_key(pam_handle_t *pamh, char **key, size_t key_size) { int fd = 0; ssize_t bytes_read = 0; - char * tmp = NULL; - - fd = open("/dev/urandom", O_RDONLY); - if (fd == -1) { - pam_syslog(pamh, LOG_ERR, "Cannot open /dev/urandom: %m"); - return PAM_AUTH_ERR; - } + char *tmp = *key = NULL; tmp = malloc(key_size); if (!tmp) { pam_syslog(pamh, LOG_CRIT, "Not enough memory"); - close(fd); + return PAM_AUTH_ERR; + } + + fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + pam_syslog(pamh, LOG_ERR, "Cannot open /dev/urandom: %m"); + pam_overwrite_n(tmp, key_size); + free(tmp); return PAM_AUTH_ERR; } |