diff options
author | 2014-06-26 19:23:15 +0000 | |
---|---|---|
committer | 2014-06-26 19:23:15 +0000 | |
commit | 25c2b03a0ad490a8369d574facf9f9513f62f56c (patch) | |
tree | 1fb22a388b16820ea12bde64c16609aa9f7ea778 /lib/libc/crypt/arc4random.c | |
parent | Document that mmap() confirms to POSIX 2008, except that we generate (diff) | |
download | wireguard-openbsd-25c2b03a0ad490a8369d574facf9f9513f62f56c.tar.xz wireguard-openbsd-25c2b03a0ad490a8369d574facf9f9513f62f56c.zip |
Add back an #ifndef MAP_INHERIT_ZERO chunk to support the old getpid()
mechanism, to aid in portability to other systems as requested.
ok matthew
Diffstat (limited to 'lib/libc/crypt/arc4random.c')
-rw-r--r-- | lib/libc/crypt/arc4random.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/libc/crypt/arc4random.c b/lib/libc/crypt/arc4random.c index a306c6d8ab3..ee47b2df340 100644 --- a/lib/libc/crypt/arc4random.c +++ b/lib/libc/crypt/arc4random.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random.c,v 1.37 2014/06/25 04:22:08 deraadt Exp $ */ +/* $OpenBSD: arc4random.c,v 1.38 2014/06/26 19:23:15 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres <dm@uun.org> @@ -74,8 +74,10 @@ _rs_init(u_char *buf, size_t n) if ((rs = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) abort(); +#ifdef MAP_INHERIT_ZERO if (minherit(rs, sizeof(*rs), MAP_INHERIT_ZERO) == -1) abort(); +#endif } if (rsx == NULL) { if ((rsx = mmap(NULL, sizeof(*rsx), PROT_READ|PROT_WRITE, @@ -111,6 +113,16 @@ _rs_stir(void) static inline void _rs_stir_if_needed(size_t len) { +#ifndef MAP_INHERIT_ZERO + static pid_t _rs_pid = 0; + pid_t pid = getpid(); + + /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */ + if (_rs_pid == 0 || _rs_pid != pid) { + _rs_pid = pid; + rs->rs_count = 0; + } +#endif if (!rs || rs->rs_count <= len) _rs_stir(); if (rs->rs_count <= len) |