mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Ensure that /dev/urandom is a char device.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifndef _WIN32
|
||||
# include <sys/stat.h>
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
@@ -107,17 +108,23 @@ safe_read(const int fd, void * const buf_, size_t count)
|
||||
static int
|
||||
randombytes_salsa20_random_random_dev_open(void)
|
||||
{
|
||||
static const char * const devices[] = {
|
||||
struct stat st;
|
||||
static const char *devices[] = {
|
||||
# ifndef USE_BLOCKING_RANDOM
|
||||
"/dev/urandom",
|
||||
# endif
|
||||
"/dev/random", NULL
|
||||
};
|
||||
const char * const *device = devices;
|
||||
const char ** device = devices;
|
||||
int fd;
|
||||
|
||||
do {
|
||||
if (access(*device, F_OK | R_OK) == 0) {
|
||||
return open(*device, O_RDONLY);
|
||||
if (access(*device, F_OK | R_OK) == 0 &&
|
||||
(fd = open(*device, O_RDONLY)) != -1) {
|
||||
if (fstat(fd, &st) == 0 && S_ISCHR(st.st_mode)) {
|
||||
return fd;
|
||||
}
|
||||
(void) close(fd);
|
||||
}
|
||||
device++;
|
||||
} while (*device != NULL);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifndef _WIN32
|
||||
# include <sys/stat.h>
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
@@ -99,17 +100,23 @@ safe_read(const int fd, void * const buf_, size_t count)
|
||||
static int
|
||||
randombytes_sysrandom_random_dev_open(void)
|
||||
{
|
||||
static const char * const devices[] = {
|
||||
struct stat st;
|
||||
static const char *devices[] = {
|
||||
# ifndef USE_BLOCKING_RANDOM
|
||||
"/dev/urandom",
|
||||
# endif
|
||||
"/dev/random", NULL
|
||||
};
|
||||
const char * const *device = devices;
|
||||
const char ** device = devices;
|
||||
int fd;
|
||||
|
||||
do {
|
||||
if (access(*device, F_OK | R_OK) == 0) {
|
||||
return open(*device, O_RDONLY);
|
||||
if (access(*device, F_OK | R_OK) == 0 &&
|
||||
(fd = open(*device, O_RDONLY)) != -1) {
|
||||
if (fstat(fd, &st) == 0 && S_ISCHR(st.st_mode)) {
|
||||
return fd;
|
||||
}
|
||||
(void) close(fd);
|
||||
}
|
||||
device++;
|
||||
} while (*device != NULL);
|
||||
|
||||
Reference in New Issue
Block a user