Skip to content

Commit

Permalink
rand_r(): Separate seed and random number
Browse files Browse the repository at this point in the history
Enforces originally intended usage of rand_r()'s API.
Mostly just paranoia, maybe.
  • Loading branch information
ydahhrk committed Jul 3, 2024
1 parent d5e3074 commit 19f3972
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/object/manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,21 @@ build_rpp(struct Manifest *mft, struct rpki_uri *notif,
struct rpki_uri *mft_uri, struct rpp **pp)
{
char const *tal;
int i, j;
unsigned int i, j;
struct FileAndHash *fah, *tmpfah;
struct rpki_uri *uri;
int error;
unsigned int rnd;
unsigned int seed, rnd;

rnd = time(NULL) ^ getpid();
seed = time(NULL) ^ getpid();

*pp = rpp_create();

tal = tal_get_file_name(validation_tal(state_retrieve()));

/* Fisher-Yates shuffle with modulo bias */
for (i = 0; i < mft->fileList.list.count - 1; i++) {
rnd = rand_r(&rnd);
rnd = rand_r(&seed);
j = i + rnd % (mft->fileList.list.count - i);
tmpfah = mft->fileList.list.array[j];
mft->fileList.list.array[j] = mft->fileList.list.array[i];
Expand Down

0 comments on commit 19f3972

Please sign in to comment.