Only use getrandom on recent glibc, when TLS not in use.
This commit is contained in:
parent
4564ff1232
commit
1a3eaeabce
@ -28,9 +28,11 @@ Contributors:
|
|||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#if !defined(WITH_TLS) && defined(__linux__)
|
||||||
|
# if defined(__GLIBC__) && __GLIBC_PREREQ(2, 25)
|
||||||
# include <sys/random.h>
|
# include <sys/random.h>
|
||||||
# endif
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_TLS
|
#ifdef WITH_TLS
|
||||||
# include <openssl/bn.h>
|
# include <openssl/bn.h>
|
||||||
@ -310,8 +312,7 @@ int util__random_bytes(void *bytes, int count)
|
|||||||
if(RAND_bytes(bytes, count) == 1){
|
if(RAND_bytes(bytes, count) == 1){
|
||||||
rc = MOSQ_ERR_SUCCESS;
|
rc = MOSQ_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
#else
|
#elif defined(__GLIBC__) && __GLIBC_PREREQ(2, 25)
|
||||||
# ifdef __GLIBC__
|
|
||||||
if(getrandom(bytes, count, 0) == 0){
|
if(getrandom(bytes, count, 0) == 0){
|
||||||
rc = MOSQ_ERR_SUCCESS;
|
rc = MOSQ_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -334,7 +335,6 @@ int util__random_bytes(void *bytes, int count)
|
|||||||
((uint8_t *)bytes)[i] = (uint8_t )(random()&0xFF);
|
((uint8_t *)bytes)[i] = (uint8_t )(random()&0xFF);
|
||||||
}
|
}
|
||||||
rc = MOSQ_ERR_SUCCESS;
|
rc = MOSQ_ERR_SUCCESS;
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user