ipc/chromium/src/third_party/libevent/mac-arc4random-buf.patch

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 --- a/evutil_rand.c 2012-08-02 10:36:53.000000000 -0500
michael@0 2 +++ b/evutil_rand.c 2013-02-20 13:01:45.000000000 -0600
michael@0 3 @@ -58,27 +58,16 @@ evutil_secure_rng_global_setup_locks_(co
michael@0 4 static void
michael@0 5 ev_arc4random_buf(void *buf, size_t n)
michael@0 6 {
michael@0 7 #if defined(_EVENT_HAVE_ARC4RANDOM_BUF) && !defined(__APPLE__)
michael@0 8 return arc4random_buf(buf, n);
michael@0 9 #else
michael@0 10 unsigned char *b = buf;
michael@0 11
michael@0 12 -#if defined(_EVENT_HAVE_ARC4RANDOM_BUF)
michael@0 13 - /* OSX 10.7 introducd arc4random_buf, so if you build your program
michael@0 14 - * there, you'll get surprised when older versions of OSX fail to run.
michael@0 15 - * To solve this, we can check whether the function pointer is set,
michael@0 16 - * and fall back otherwise. (OSX does this using some linker
michael@0 17 - * trickery.)
michael@0 18 - */
michael@0 19 - if (arc4random_buf != NULL) {
michael@0 20 - return arc4random_buf(buf, n);
michael@0 21 - }
michael@0 22 -#endif
michael@0 23 /* Make sure that we start out with b at a 4-byte alignment; plenty
michael@0 24 * of CPUs care about this for 32-bit access. */
michael@0 25 if (n >= 4 && ((ev_uintptr_t)b) & 3) {
michael@0 26 ev_uint32_t u = arc4random();
michael@0 27 int n_bytes = 4 - (((ev_uintptr_t)b) & 3);
michael@0 28 memcpy(b, &u, n_bytes);
michael@0 29 b += n_bytes;
michael@0 30 n -= n_bytes;

mercurial