diff options
author | 2016-05-23 20:47:49 +0000 | |
---|---|---|
committer | 2016-05-23 20:47:49 +0000 | |
commit | 97653aec6885285ab7fb5e40fc242c19d1843487 (patch) | |
tree | 8d6f95916e9c93ac29fa7c1f9c509e9675960edb | |
parent | Use a fixed buffer for strftime() because there is no portable way to (diff) | |
download | wireguard-openbsd-97653aec6885285ab7fb5e40fc242c19d1843487.tar.xz wireguard-openbsd-97653aec6885285ab7fb5e40fc242c19d1843487.zip |
Use arc4random_uniform() instead of arc4random() to avoid modulus bias.
This eliminates the idiom 'arc4random() % X' (where X + 1 is not a
power of two) from base.
Part of a patch from Matthew Martin from end of last year.
ok tedu@ (a long time ago), natano@
-rw-r--r-- | sys/ufs/ffs/ffs_alloc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index 61787119859..7c6bc8c27ff 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs_alloc.c,v 1.107 2016/05/23 09:31:28 natano Exp $ */ +/* $OpenBSD: ffs_alloc.c,v 1.108 2016/05/23 20:47:49 tb Exp $ */ /* $NetBSD: ffs_alloc.c,v 1.11 1996/05/11 18:27:09 mycroft Exp $ */ /* @@ -468,7 +468,7 @@ ffs_dirpref(struct inode *pip) * Force allocation in another cg if creating a first level dir. */ if (ITOV(pip)->v_flag & VROOT) { - prefcg = (arc4random() & INT_MAX) % fs->fs_ncg; + prefcg = arc4random_uniform(fs->fs_ncg); mincg = prefcg; minndir = fs->fs_ipg; for (cg = prefcg; cg < fs->fs_ncg; cg++) |