From: Michihiro NAKAJIMA Date: Mon, 13 Oct 2014 08:31:50 +0000 (+0900) Subject: Use archive_random() function instead of rand() function. X-Git-Tag: v3.1.900a~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9422ef8a55cbe4f738336de30160ca103644b81;p=thirdparty%2Flibarchive.git Use archive_random() function instead of rand() function. --- diff --git a/libarchive/archive_util.c b/libarchive/archive_util.c index 3a951c819..12e419f64 100644 --- a/libarchive/archive_util.c +++ b/libarchive/archive_util.c @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:1 #include "archive.h" #include "archive_private.h" +#include "archive_random_private.h" #include "archive_string.h" #ifndef O_CLOEXEC @@ -471,7 +472,6 @@ __archive_mktemp(const char *tmpdir) struct stat st; int fd; char *tp, *ep; - unsigned seed; fd = -1; archive_string_init(&temp_name); @@ -495,21 +495,15 @@ __archive_mktemp(const char *tmpdir) archive_strcat(&temp_name, "XXXXXXXXXX"); ep = temp_name.s + archive_strlen(&temp_name); - fd = open("/dev/random", O_RDONLY | O_CLOEXEC); - __archive_ensure_cloexec_flag(fd); - if (fd < 0) - seed = time(NULL); - else { - if (read(fd, &seed, sizeof(seed)) < 0) - seed = time(NULL); - close(fd); - } do { char *p; p = tp; - while (p < ep) - *p++ = num[((unsigned)rand_r(&seed)) % sizeof(num)]; + archive_random(p, ep - p); + while (p < ep) { + int d = *((unsigned char *)p) % sizeof(num); + *p++ = num[d]; + } fd = open(temp_name.s, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, 0600); } while (fd < 0 && errno == EEXIST); diff --git a/libarchive/archive_write_set_format_warc.c b/libarchive/archive_write_set_format_warc.c index 75e8f4ef9..9623d717f 100644 --- a/libarchive/archive_write_set_format_warc.c +++ b/libarchive/archive_write_set_format_warc.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include "archive_entry.h" #include "archive_entry_locale.h" #include "archive_private.h" +#include "archive_random_private.h" #include "archive_write_private.h" struct warc_s { @@ -141,7 +142,6 @@ archive_write_set_format_warc(struct archive *_a) w->typ = 0; /* also initialise our rng */ w->rng = (unsigned int)w->now; - srand(w->rng); a->format_data = w; a->format_name = "WARC/1.0"; @@ -427,10 +427,7 @@ _popul_ehdr(struct archive_string *tgt, size_t tsz, warc_essential_hdr_t hdr) static int _gen_uuid(warc_uuid_t *tgt) { - tgt->u[0U] = (unsigned int)rand(); - tgt->u[1U] = (unsigned int)rand(); - tgt->u[2U] = (unsigned int)rand(); - tgt->u[3U] = (unsigned int)rand(); + archive_random(tgt->u, sizeof(tgt->u)); /* obey uuid version 4 rules */ tgt->u[1U] &= 0xffff0fffU; tgt->u[1U] |= 0x4000U;