diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-08-23 13:37:47 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-08-23 13:37:47 +0100 |
commit | deddd071765839a9327058a260f253d52f12355a (patch) | |
tree | bbb45155934426f581e410604d60f74f0be1065c | |
parent | 792a1ecee836d659d299b31066a9f1df43d0922e (diff) | |
download | rspamd-deddd071765839a9327058a260f253d52f12355a.tar.gz rspamd-deddd071765839a9327058a260f253d52f12355a.zip |
[Minor] Do not use crypto PRG for mempool uids
-rw-r--r-- | src/libutil/mem_pool.c | 11 | ||||
-rw-r--r-- | src/libutil/mem_pool.h | 4 |
2 files changed, 6 insertions, 9 deletions
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index bbd302a23..02b5ed3c4 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -284,7 +284,6 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) { rspamd_mempool_t *new_pool; gpointer map; - unsigned char uidbuf[10]; const gchar hexdigits[] = "0123456789abcdef"; unsigned i; @@ -405,12 +404,10 @@ rspamd_mempool_new_(gsize size, const gchar *tag, gint flags, const gchar *loc) } /* Generate new uid */ - ottery_rand_bytes(uidbuf, sizeof(uidbuf)); - for (i = 0; i < G_N_ELEMENTS(uidbuf); i++) { - new_pool->tag.uid[i * 2] = hexdigits[(uidbuf[i] >> 4) & 0xf]; - new_pool->tag.uid[i * 2 + 1] = hexdigits[uidbuf[i] & 0xf]; - } - new_pool->tag.uid[19] = '\0'; + uint64_t uid = rspamd_random_uint64_fast(); + rspamd_encode_hex_buf((unsigned char *) &uid, sizeof(uid), + new_pool->tag.uid, sizeof(new_pool->tag.uid) - 1); + new_pool->tag.uid[sizeof(new_pool->tag.uid) - 1] = '\0'; mem_pool_stat->pools_allocated++; diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 425a6b297..aea5f4ae8 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -70,8 +70,8 @@ struct f_str_s; #define RSPAMD_ATTR_RETURNS_NONNUL #endif -#define MEMPOOL_TAG_LEN 20 -#define MEMPOOL_UID_LEN 20 +#define MEMPOOL_TAG_LEN 16 +#define MEMPOOL_UID_LEN 16 /* All pointers are aligned as this variable */ #define MIN_MEM_ALIGNMENT G_MEM_ALIGN |