Compare commits
2 Commits
cb014e58e7
...
592424c114
| Author | SHA1 | Date |
|---|---|---|
|
|
592424c114 | |
|
|
963423df59 |
3
HISTORY
3
HISTORY
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
Version 1.85 2026-06-08
|
||||||
|
* add functions fc_safe_srand and fc_safe_rand for more security under Linux
|
||||||
|
|
||||||
Version 1.84 2026-01-16
|
Version 1.84 2026-01-16
|
||||||
* fast_task_queue.h: add function free_queue_task_arg_offset
|
* fast_task_queue.h: add function free_queue_task_arg_offset
|
||||||
* add function double2str and double_to_comma_str
|
* add function double2str and double_to_comma_str
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ int fast_allocator_init_ex(struct fast_allocator_context *acontext,
|
||||||
struct fast_region_info *pRegion;
|
struct fast_region_info *pRegion;
|
||||||
struct fast_region_info *region_end;
|
struct fast_region_info *region_end;
|
||||||
|
|
||||||
srand(time(NULL));
|
set_rand_seed();
|
||||||
memset(acontext, 0, sizeof(*acontext));
|
memset(acontext, 0, sizeof(*acontext));
|
||||||
if (region_count <= 0)
|
if (region_count <= 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "shared_func.h"
|
||||||
#include "fc_memory.h"
|
#include "fc_memory.h"
|
||||||
#include "flat_skiplist.h"
|
#include "flat_skiplist.h"
|
||||||
|
|
||||||
|
|
@ -111,7 +112,7 @@ int flat_skiplist_init_ex(FlatSkiplist *sl, const int level_count,
|
||||||
sl->compare_func = compare_func;
|
sl->compare_func = compare_func;
|
||||||
sl->free_func = free_func;
|
sl->free_func = free_func;
|
||||||
|
|
||||||
srand(time(NULL));
|
set_rand_seed();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "shared_func.h"
|
||||||
#include "fc_memory.h"
|
#include "fc_memory.h"
|
||||||
#include "multi_skiplist.h"
|
#include "multi_skiplist.h"
|
||||||
|
|
||||||
|
|
@ -118,7 +119,7 @@ int multi_skiplist_init_ex(MultiSkiplist *sl, const int level_count,
|
||||||
sl->compare_func = compare_func;
|
sl->compare_func = compare_func;
|
||||||
sl->free_func = free_func;
|
sl->free_func = free_func;
|
||||||
|
|
||||||
srand(time(NULL));
|
set_rand_seed();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2486,19 +2486,15 @@ int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes)
|
||||||
|
|
||||||
int set_rand_seed()
|
int set_rand_seed()
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
time_t ts;
|
||||||
|
int64_t ns;
|
||||||
|
uint32_t seed;
|
||||||
|
|
||||||
if (gettimeofday(&tv, NULL) != 0)
|
ns = get_current_time_ns();
|
||||||
{
|
time(&ts);
|
||||||
logError("file: "__FILE__", line: %d, " \
|
seed = ts ^ (ns & 0xFFFFFFFF);
|
||||||
"call gettimeofday fail, " \
|
srand(seed);
|
||||||
"errno=%d, error info: %s", \
|
return 0;
|
||||||
__LINE__, errno, STRERROR(errno));
|
|
||||||
return errno != 0 ? errno : EPERM;
|
|
||||||
}
|
|
||||||
|
|
||||||
srand(tv.tv_sec ^ tv.tv_usec);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_time_item_from_conf_ex(IniFullContext *ini_ctx,
|
int get_time_item_from_conf_ex(IniFullContext *ini_ctx,
|
||||||
|
|
@ -4555,3 +4551,32 @@ const char *double2str(const double d, const int scale,
|
||||||
memcpy(buff + new_len, fragment, tail_len + 1);
|
memcpy(buff + new_len, fragment, tail_len + 1);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OS_LINUX
|
||||||
|
|
||||||
|
#ifndef __NR_getrandom
|
||||||
|
#define __NR_getrandom 318
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void fc_safe_srand()
|
||||||
|
{
|
||||||
|
uint32_t seed;
|
||||||
|
|
||||||
|
if (syscall(__NR_getrandom, &seed, sizeof(seed), 0) != sizeof(seed)) {
|
||||||
|
set_rand_seed();
|
||||||
|
} else {
|
||||||
|
srand(seed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fc_safe_rand()
|
||||||
|
{
|
||||||
|
uint32_t n;
|
||||||
|
|
||||||
|
if (syscall(__NR_getrandom, &n, sizeof(n), 0) != sizeof(n)) {
|
||||||
|
return rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (n & RAND_MAX);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1867,6 +1867,14 @@ static inline size_t fc_iov_get_bytes(const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OS_LINUX
|
||||||
|
void fc_safe_srand();
|
||||||
|
int fc_safe_rand();
|
||||||
|
#else
|
||||||
|
#define fc_safe_srand() set_rand_seed()
|
||||||
|
#define fc_safe_rand() rand()
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "shared_func.h"
|
||||||
#include "fc_memory.h"
|
#include "fc_memory.h"
|
||||||
#include "skiplist_set.h"
|
#include "skiplist_set.h"
|
||||||
|
|
||||||
|
|
@ -110,7 +111,7 @@ int skiplist_set_init_ex(SkiplistSet *sl, const int level_count,
|
||||||
sl->compare_func = compare_func;
|
sl->compare_func = compare_func;
|
||||||
sl->free_func = free_func;
|
sl->free_func = free_func;
|
||||||
|
|
||||||
srand(time(NULL));
|
set_rand_seed();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "shared_func.h"
|
||||||
#include "fc_memory.h"
|
#include "fc_memory.h"
|
||||||
#include "uniq_skiplist.h"
|
#include "uniq_skiplist.h"
|
||||||
|
|
||||||
|
|
@ -138,7 +139,7 @@ int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory,
|
||||||
factory->delay_free_seconds = delay_free_seconds;
|
factory->delay_free_seconds = delay_free_seconds;
|
||||||
factory->arg = arg;
|
factory->arg = arg;
|
||||||
|
|
||||||
srand(time(NULL));
|
set_rand_seed();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue