Skip to content

Commit

Permalink
[Minor] Do not use crypto PRG for mempool uids
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Aug 23, 2023
1 parent 792a1ec commit deddd07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/libutil/mem_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++;

Expand Down
4 changes: 2 additions & 2 deletions src/libutil/mem_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit deddd07

Please sign in to comment.