From: Job Snijders Date: Tue, 25 Jun 2024 07:24:04 +0000 (+0000) Subject: Use thread-safe PRNG X-Git-Tag: 1.6.3~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F141%2Fhead;p=thirdparty%2FFORT-validator.git Use thread-safe PRNG rand() isn't thread-safe on all platforms (musl libc for example) use rand_r() instead --- diff --git a/src/object/manifest.c b/src/object/manifest.c index 7f188e2e..779d2f40 100644 --- a/src/object/manifest.c +++ b/src/object/manifest.c @@ -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;