From deddd071765839a9327058a260f253d52f12355a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 23 Aug 2023 13:37:47 +0100 Subject: [PATCH] [Minor] Do not use crypto PRG for mempool uids --- src/libutil/mem_pool.c | 11 ++++------- 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 -- 2.39.5