diff options
| author | deraadt <> | 2014-06-26 19:23:15 +0000 |
|---|---|---|
| committer | deraadt <> | 2014-06-26 19:23:15 +0000 |
| commit | e1099ee6a37fa7669fe4946d8b78464418cce894 (patch) | |
| tree | f5ac8595f57af15ba5b781fc8cbacbed08962a43 /src/lib/libc/crypt/arc4random.c | |
| parent | ce913a2bba7ab65c50f4c8b5b17699b3e85de6a6 (diff) | |
| download | openbsd-e1099ee6a37fa7669fe4946d8b78464418cce894.tar.gz openbsd-e1099ee6a37fa7669fe4946d8b78464418cce894.tar.bz2 openbsd-e1099ee6a37fa7669fe4946d8b78464418cce894.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 'src/lib/libc/crypt/arc4random.c')
| -rw-r--r-- | src/lib/libc/crypt/arc4random.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/lib/libc/crypt/arc4random.c b/src/lib/libc/crypt/arc4random.c index a306c6d8ab..ee47b2df34 100644 --- a/src/lib/libc/crypt/arc4random.c +++ b/src/lib/libc/crypt/arc4random.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: arc4random.c,v 1.37 2014/06/25 04:22:08 deraadt Exp $ */ | 1 | /* $OpenBSD: arc4random.c,v 1.38 2014/06/26 19:23:15 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> | 4 | * Copyright (c) 1996, David Mazieres <dm@uun.org> |
| @@ -74,8 +74,10 @@ _rs_init(u_char *buf, size_t n) | |||
| 74 | if ((rs = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE, | 74 | if ((rs = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE, |
| 75 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) | 75 | MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) |
| 76 | abort(); | 76 | abort(); |
| 77 | #ifdef MAP_INHERIT_ZERO | ||
| 77 | if (minherit(rs, sizeof(*rs), MAP_INHERIT_ZERO) == -1) | 78 | if (minherit(rs, sizeof(*rs), MAP_INHERIT_ZERO) == -1) |
| 78 | abort(); | 79 | abort(); |
| 80 | #endif | ||
| 79 | } | 81 | } |
| 80 | if (rsx == NULL) { | 82 | if (rsx == NULL) { |
| 81 | if ((rsx = mmap(NULL, sizeof(*rsx), PROT_READ|PROT_WRITE, | 83 | if ((rsx = mmap(NULL, sizeof(*rsx), PROT_READ|PROT_WRITE, |
| @@ -111,6 +113,16 @@ _rs_stir(void) | |||
| 111 | static inline void | 113 | static inline void |
| 112 | _rs_stir_if_needed(size_t len) | 114 | _rs_stir_if_needed(size_t len) |
| 113 | { | 115 | { |
| 116 | #ifndef MAP_INHERIT_ZERO | ||
| 117 | static pid_t _rs_pid = 0; | ||
| 118 | pid_t pid = getpid(); | ||
| 119 | |||
| 120 | /* If a system lacks MAP_INHERIT_ZERO, resort to getpid() */ | ||
| 121 | if (_rs_pid == 0 || _rs_pid != pid) { | ||
| 122 | _rs_pid = pid; | ||
| 123 | rs->rs_count = 0; | ||
| 124 | } | ||
| 125 | #endif | ||
| 114 | if (!rs || rs->rs_count <= len) | 126 | if (!rs || rs->rs_count <= len) |
| 115 | _rs_stir(); | 127 | _rs_stir(); |
| 116 | if (rs->rs_count <= len) | 128 | if (rs->rs_count <= len) |
