From b36c181bfc0d75f461c892782259c2c2acc29394 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mar 23 2020 20:18:19 +0000 Subject: Use getrandom() for random numbers Although this place id not cryptgraphically relevant, there is no point in not using a proper random value. This happens only once so it is not a performance issue. Signed-off-by: Simo Sorce --- diff --git a/src/client/gpm_common.c b/src/client/gpm_common.c index 808f350..60b1fdc 100644 --- a/src/client/gpm_common.c +++ b/src/client/gpm_common.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #define FRAGMENT_BIT (1 << 31) @@ -41,7 +42,9 @@ pthread_once_t gpm_init_once_control = PTHREAD_ONCE_INIT; static void gpm_init_once(void) { pthread_mutexattr_t attr; - unsigned int seedp; + char *buf = (char *)&gpm_global_ctx.next_xid; + size_t len = sizeof(gpm_global_ctx.next_xid); + size_t ret = 0; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); @@ -52,8 +55,9 @@ static void gpm_init_once(void) gpm_global_ctx.epollfd = -1; gpm_global_ctx.timerfd = -1; - seedp = time(NULL) + getpid() + pthread_self(); - gpm_global_ctx.next_xid = rand_r(&seedp); + while(ret < len) { + ret += getrandom(buf + ret, len - ret, 0); + } pthread_mutexattr_destroy(&attr);