]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Use thread-safe PRNG 141/head
authorJob Snijders <job@sobornost.net>
Tue, 25 Jun 2024 07:24:04 +0000 (07:24 +0000)
committerJob Snijders <job@sobornost.net>
Tue, 25 Jun 2024 07:24:04 +0000 (07:24 +0000)
rand() isn't thread-safe on all platforms (musl libc for example)
use rand_r() instead

src/object/manifest.c

index 7f188e2e9c20acb309c34ea1099a73c1c0829788..779d2f40bfafe0cb163342dee8e7bd18b7d2b1de 100644 (file)
@@ -198,15 +198,18 @@ build_rpp(struct Manifest *mft, struct rpki_uri *notif,
        struct FileAndHash *fah, *tmpfah;
        struct rpki_uri *uri;
        int error;
+       unsigned int rnd;
+
+       rnd = time(NULL) ^ getpid();
 
        *pp = rpp_create();
 
        tal = tal_get_file_name(validation_tal(state_retrieve()));
 
        /* Fisher-Yates shuffle with modulo bias */
-       srand(time(NULL) ^ getpid());
        for (i = 0; i < mft->fileList.list.count - 1; i++) {
-               j = i + rand() % (mft->fileList.list.count - i);
+               rnd = rand_r(&rnd);
+               j = i + rnd % (mft->fileList.list.count - i);
                tmpfah = mft->fileList.list.array[j];
                mft->fileList.list.array[j] = mft->fileList.list.array[i];
                mft->fileList.list.array[i] = tmpfah;