]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use archive_random() function instead of rand() function.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 13 Oct 2014 08:31:50 +0000 (17:31 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 13 Oct 2014 09:03:30 +0000 (18:03 +0900)
libarchive/archive_util.c
libarchive/archive_write_set_format_warc.c

index 3a951c819afbe2c0ee80fa2346ae28c67ec204df..12e419f645fe2638ee755d8e946906cd7b9e206b 100644 (file)
@@ -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);
index 75e8f4ef93885722a590a557c5730b6132bba9bb..9623d717feb7bd876c9f27c33dfaa691cb365791 100644 (file)
@@ -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;