Browse Source

Use arc4random_buf() when requesting more than a single word of output

Use arc4random_uniform() when the desired random number upper bound
is not a power of two
ok deraadt@ millert@
OPENBSD_4_4
djm 16 years ago
parent
commit
d34ab18f72
2 changed files with 5 additions and 5 deletions
  1. +2
    -2
      src/lib/libc/stdlib/malloc.c
  2. +3
    -3
      src/usr.sbin/ntpd/ntp.c

+ 2
- 2
src/lib/libc/stdlib/malloc.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: malloc.c,v 1.88 2008/02/20 18:31:34 otto Exp $ */
/* $OpenBSD: malloc.c,v 1.89 2008/04/13 00:22:16 djm Exp $ */
/* /*
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
@ -1140,7 +1140,7 @@ malloc_bytes(size_t size)
if (malloc_guard) { if (malloc_guard) {
/* Walk to a random position. */ /* Walk to a random position. */
i = arc4random() % bp->free;
i = arc4random_uniform(bp->free);
while (i > 0) { while (i > 0) {
u += u; u += u;
k++; k++;


+ 3
- 3
src/usr.sbin/ntpd/ntp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.103 2008/01/28 11:45:59 mpf Exp $ */
/* $OpenBSD: ntp.c,v 1.104 2008/04/13 00:22:17 djm Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -659,7 +659,7 @@ scale_interval(time_t requested)
time_t interval, r; time_t interval, r;
interval = requested * conf->scale; interval = requested * conf->scale;
r = arc4random() % MAX(5, interval / 10);
r = arc4random_uniform(MAX(5, interval / 10));
return (interval + r); return (interval + r);
} }
@ -669,7 +669,7 @@ error_interval(void)
time_t interval, r; time_t interval, r;
interval = INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN; interval = INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
r = arc4random() % (interval / 10);
r = arc4random_uniform(interval / 10);
return (interval + r); return (interval + r);
} }


Loading…
Cancel
Save