Browse Source

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
OPENBSD_5_6
deraadt 10 years ago
parent
commit
b6b255face
1 changed files with 13 additions and 1 deletions
  1. +13
    -1
      src/lib/libc/crypt/arc4random.c

+ 13
- 1
src/lib/libc/crypt/arc4random.c View File

@ -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> * 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, if ((rs = mmap(NULL, sizeof(*rs), PROT_READ|PROT_WRITE,
MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
abort(); abort();
#ifdef MAP_INHERIT_ZERO
if (minherit(rs, sizeof(*rs), MAP_INHERIT_ZERO) == -1) if (minherit(rs, sizeof(*rs), MAP_INHERIT_ZERO) == -1)
abort(); abort();
#endif
} }
if (rsx == NULL) { if (rsx == NULL) {
if ((rsx = mmap(NULL, sizeof(*rsx), PROT_READ|PROT_WRITE, if ((rsx = mmap(NULL, sizeof(*rsx), PROT_READ|PROT_WRITE,
@ -111,6 +113,16 @@ _rs_stir(void)
static inline void static inline void
_rs_stir_if_needed(size_t len) _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) if (!rs || rs->rs_count <= len)
_rs_stir(); _rs_stir();
if (rs->rs_count <= len) if (rs->rs_count <= len)


Loading…
Cancel
Save