[haiku-commits] haiku: hrev51354 - src/system/libroot/posix/stdlib

  • From: philippe.houdoin@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 9 Aug 2017 19:34:02 +0200 (CEST)

hrev51354 adds 1 changeset to branch 'master'
old head: ed8aae4664e836854f0c0e4751dfc19e634e4bfb
new head: c7a3a80cc62aa1f52863b96e4a06dca9a93e5423
overview: 
http://cgit.haiku-os.org/haiku/log/?qt=range&q=c7a3a80cc62a+%5Eed8aae4664e8

----------------------------------------------------------------------------

c7a3a80cc62a: libroot: make mktemp() more random
  ... by seeding rand() with process id, user id and current time.
  This fix #13660

                           [ Philippe Houdoin <philippe.houdoin@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev51354
Commit:      c7a3a80cc62aa1f52863b96e4a06dca9a93e5423
URL:         http://cgit.haiku-os.org/haiku/commit/?id=c7a3a80cc62a
Author:      Philippe Houdoin <philippe.houdoin@xxxxxxxxx>
Date:        Wed Aug  9 19:30:15 2017 UTC

Ticket:      https://dev.haiku-os.org/ticket/13660

----------------------------------------------------------------------------

1 file changed, 5 insertions(+)
src/system/libroot/posix/stdlib/mktemp.c | 5 +++++

----------------------------------------------------------------------------

diff --git a/src/system/libroot/posix/stdlib/mktemp.c 
b/src/system/libroot/posix/stdlib/mktemp.c
index 1d1d999..03d81fe 100644
--- a/src/system/libroot/posix/stdlib/mktemp.c
+++ b/src/system/libroot/posix/stdlib/mktemp.c
@@ -33,6 +33,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <stdio.h>
@@ -96,6 +97,7 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
        char *pad;
        struct stat sbuf;
        int rval;
+       struct timeval tv;
 
        if (doopen != NULL && domkdir) {
                __set_errno(EINVAL);
@@ -114,6 +116,9 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
        }
 
        /* Fill space with random characters */
+       /* seed rand() first, otherwise generated sequences are same */
+       gettimeofday(&tv, 0);
+       srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
        while (trv >= path && *trv == 'X') {
                uint32_t value = rand() % (sizeof(padchar) - 1);
                *trv-- = padchar[value];


Other related posts: