Remove unused srand() etc. functions

This commit is contained in:
Roger A. Light 2025-10-15 11:49:13 +01:00
parent a566e1a3ec
commit 0ba2436589
5 changed files with 7 additions and 44 deletions

View file

@ -65,26 +65,6 @@ int mosquitto_lib_init(void)
if(init_refcount == 0){
mosquitto_time_init();
#ifdef WIN32
srand((unsigned int)GetTickCount64());
#elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK)
struct timespec tp;
#ifdef CLOCK_BOOTTIME
if(clock_gettime(CLOCK_BOOTTIME, &tp) != 0)
#endif
clock_gettime(CLOCK_MONOTONIC, &tp);
srand((unsigned int)tp.tv_nsec);
#elif defined(__APPLE__)
uint64_t ticks;
ticks = mach_absolute_time();
srand((unsigned int)ticks);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
srand(tv.tv_sec*1000 + tv.tv_usec/1000);
#endif
rc = net__init();
if(rc != MOSQ_ERR_SUCCESS){

View file

@ -31,16 +31,8 @@ Contributors:
# include <sys/stat.h>
#endif
#if !defined(WITH_TLS) && defined(__linux__) && defined(__GLIBC__)
# if __GLIBC_PREREQ(2, 25)
# include <sys/random.h>
# define HAVE_GETRANDOM 1
# endif
#endif
#ifdef WITH_TLS
# include <openssl/bn.h>
# include <openssl/rand.h>
#endif
#ifdef WITH_BROKER

View file

@ -21,7 +21,6 @@ Contributors:
#ifdef WITH_TLS
# include <openssl/opensslv.h>
# include <openssl/evp.h>
# include <openssl/rand.h>
# include <openssl/buffer.h>
#endif
#include <string.h>

View file

@ -111,10 +111,6 @@ static int get_password_from_init_file(struct dynsec__data *data, char **pw)
static int generate_password(struct dynsec__data *data, cJSON *j_client, char **password)
{
struct mosquitto_pw *pw;
int i;
unsigned char vb;
unsigned long v;
size_t len;
char *pwenv;
if(data->init_mode == dpwim_file){
@ -132,12 +128,16 @@ static int generate_password(struct dynsec__data *data, cJSON *j_client, char **
return MOSQ_ERR_NOMEM;
}
}else{
*password = malloc(21);
unsigned char vb;
unsigned long v;
size_t len;
const size_t pwlen = 20;
*password = malloc(pwlen+1);
if(*password == NULL){
return MOSQ_ERR_NOMEM;
}
len = sizeof(pw_chars)-1;
for(i=0; i<20; i++){
for(size_t i=0; i<pwlen; i++){
do{
if(RAND_bytes(&vb, 1) != 1){
free(*password);
@ -147,7 +147,7 @@ static int generate_password(struct dynsec__data *data, cJSON *j_client, char **
}while(v >= (RAND_MAX - (RAND_MAX % len)));
(*password)[i] = pw_chars[v%len];
}
(*password)[20] = '\0';
(*password)[pwlen] = '\0';
}
if(mosquitto_pw_new(&pw, MOSQ_PW_DEFAULT) != MOSQ_ERR_SUCCESS

View file

@ -434,14 +434,6 @@ int main(int argc, char *argv[])
#endif
#ifdef WIN32
GetSystemTime(&st);
srand(st.wSecond + st.wMilliseconds);
#else
gettimeofday(&tv, NULL);
srand((unsigned int)(tv.tv_sec + tv.tv_usec));
#endif
#ifdef WIN32
if(_setmaxstdio(8192) != 8192){
/* Old limit was 2048 */