]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
urandom: use st_ino and st_rdev to determine device uniqueness
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 15 Jul 2016 12:58:07 +0000 (14:58 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 15 Jul 2016 13:53:10 +0000 (15:53 +0200)
lib/nettle/rnd-common.c

index f297679002afcb6a5550717a51b192a27feb40d0..5cb9e880429eedb16ac8f7313fa2f0014ce50880 100644 (file)
@@ -138,7 +138,8 @@ void _rnd_system_entropy_deinit(void)
 #include "egd.h"
 
 static int _gnutls_urandom_fd = -1;
-static mode_t _gnutls_urandom_fd_mode = 0;
+static ino_t _gnutls_urandom_fd_ino = 0;
+static dev_t _gnutls_urandom_fd_rdev = 0;
 
 
 get_entropy_func _rnd_get_system_entropy = NULL;
@@ -272,7 +273,7 @@ int _rnd_system_entropy_check(void)
                return 0;
 
        ret = fstat(_gnutls_urandom_fd, &st);
-       if (ret < 0 || st.st_mode != _gnutls_urandom_fd_mode) {
+       if (ret < 0 || st.st_ino != _gnutls_urandom_fd_ino || st.st_rdev != _gnutls_urandom_fd_rdev) {
                return _rnd_system_entropy_init();
        }
        return 0;
@@ -304,7 +305,8 @@ int _rnd_system_entropy_init(void)
                fcntl(_gnutls_urandom_fd, F_SETFD, old | FD_CLOEXEC);
 
        if (fstat(_gnutls_urandom_fd, &st) >= 0) {
-               _gnutls_urandom_fd_mode = st.st_mode;
+               _gnutls_urandom_fd_ino = st.st_ino;
+               _gnutls_urandom_fd_rdev = st.st_rdev;
        }
 
        _rnd_get_system_entropy = _rnd_get_system_entropy_urandom;
@@ -321,7 +323,8 @@ fallback:
        }
 
        if (fstat(_gnutls_urandom_fd, &st) >= 0) {
-               _gnutls_urandom_fd_mode = st.st_mode;
+               _gnutls_urandom_fd_ino = st.st_ino;
+               _gnutls_urandom_fd_rdev = st.st_rdev;
        }
 
        _gnutls_debug_log("EGD random generator was detected\n");