]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
rand_r(): Separate seed and random number
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 3 Jul 2024 18:26:59 +0000 (12:26 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 3 Jul 2024 18:33:40 +0000 (12:33 -0600)
Enforces originally intended usage of rand_r()'s API.
Mostly just paranoia, maybe.

src/object/manifest.c

index 779d2f40bfafe0cb163342dee8e7bd18b7d2b1de..bee421ce36ec97d45bf5583f210f2368cc56671f 100644 (file)
@@ -194,13 +194,13 @@ 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();
 
@@ -208,7 +208,7 @@ build_rpp(struct Manifest *mft, struct rpki_uri *notif,
 
        /* 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];