1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-24 04:25:10 -07:00

/dev/urandom can be a name special file in addition to a character special file

This commit is contained in:
Frank Denis 2015-10-05 11:51:29 +02:00
parent 4705c0a066
commit d8e870cb43
2 changed files with 14 additions and 2 deletions

View File

@ -134,7 +134,13 @@ randombytes_salsa20_random_random_dev_open(void)
do {
fd = open(*device, O_RDONLY);
if (fd != -1) {
if (fstat(fd, &st) == 0 && S_ISCHR(st.st_mode)) {
if (fstat(fd, &st) == 0 &&
# ifdef S_IFNAM
(S_IFNAM(st.st_mode) || S_ISCHR(st.st_mode))
# else
S_ISCHR(st.st_mode)
# endif
) {
# if defined(F_SETFD) && defined(FD_CLOEXEC)
(void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
# endif

View File

@ -119,7 +119,13 @@ randombytes_sysrandom_random_dev_open(void)
do {
fd = open(*device, O_RDONLY);
if (fd != -1) {
if (fstat(fd, &st) == 0 && S_ISCHR(st.st_mode)) {
if (fstat(fd, &st) == 0 &&
# ifdef S_IFNAM
(S_IFNAM(st.st_mode) || S_ISCHR(st.st_mode))
# else
S_ISCHR(st.st_mode)
# endif
) {
# if defined(F_SETFD) && defined(FD_CLOEXEC)
(void) fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
# endif