summaryrefslogtreecommitdiff
path: root/usr.sbin/npppd
diff options
context:
space:
mode:
authortb <tb@cvs.openbsd.org>2015-12-17 08:09:21 +0000
committertb <tb@cvs.openbsd.org>2015-12-17 08:09:21 +0000
commit4acc8923abc902bd69178f7ab9e85c2d7a808a0e (patch)
tree4b861d52080747f11f0f541cc15909282dfc6d69 /usr.sbin/npppd
parent9f24dd6892ff8ca7096feac476c6cdf3a83d3304 (diff)
Replace 'arc4random() % (2^k - 1)' by 'arc4random() & (2^k - 1)' to
avoid modulo bias. Part of a diff by Matthew Martin, reviewed by deraadt@ and me. ok deraadt@
Diffstat (limited to 'usr.sbin/npppd')
-rw-r--r--usr.sbin/npppd/l2tp/l2tpd.c10
-rw-r--r--usr.sbin/npppd/pppoe/pppoed.c10
2 files changed, 10 insertions, 10 deletions
diff --git a/usr.sbin/npppd/l2tp/l2tpd.c b/usr.sbin/npppd/l2tp/l2tpd.c
index 8e0b9d99c98..48c0d236fde 100644
--- a/usr.sbin/npppd/l2tp/l2tpd.c
+++ b/usr.sbin/npppd/l2tp/l2tpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: l2tpd.c,v 1.17 2015/12/05 18:43:36 mmcc Exp $ */
+/* $OpenBSD: l2tpd.c,v 1.18 2015/12/17 08:09:20 tb Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -26,7 +26,7 @@
* SUCH DAMAGE.
*/
/**@file L2TP(Layer Two Tunneling Protocol "L2TP") / RFC2661 */
-/* $Id: l2tpd.c,v 1.17 2015/12/05 18:43:36 mmcc Exp $ */
+/* $Id: l2tpd.c,v 1.18 2015/12/17 08:09:20 tb Exp $ */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
@@ -113,11 +113,11 @@ l2tpd_init(l2tpd *_this)
__func__);
return 1;
}
- off = arc4random() % L2TP_SESSION_ID_MASK;
+ off = arc4random() & L2TP_SESSION_ID_MASK;
for (i = 0; i < L2TP_NCALL; i++) {
- id = (i + off) % L2TP_SESSION_ID_MASK;
+ id = (i + off) & L2TP_SESSION_ID_MASK;
if (id == 0)
- id = (off - 1) % L2TP_SESSION_ID_MASK;
+ id = (off - 1) & L2TP_SESSION_ID_MASK;
if (slist_add(&_this->free_session_id_list,
(void *)(uintptr_t)id) == NULL) {
l2tpd_log(_this, LOG_ERR,
diff --git a/usr.sbin/npppd/pppoe/pppoed.c b/usr.sbin/npppd/pppoe/pppoed.c
index bcb71b2f7e8..10d73d517c6 100644
--- a/usr.sbin/npppd/pppoe/pppoed.c
+++ b/usr.sbin/npppd/pppoe/pppoed.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pppoed.c,v 1.18 2015/10/11 07:32:06 guenther Exp $ */
+/* $OpenBSD: pppoed.c,v 1.19 2015/12/17 08:09:20 tb Exp $ */
/*-
* Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -28,7 +28,7 @@
/**@file
* This file provides the PPPoE(RFC2516) server(access concentrator)
* implementaion.
- * $Id: pppoed.c,v 1.18 2015/10/11 07:32:06 guenther Exp $
+ * $Id: pppoed.c,v 1.19 2015/12/17 08:09:20 tb Exp $
*/
#include <sys/param.h> /* ALIGN */
#include <sys/types.h>
@@ -147,11 +147,11 @@ pppoed_init(pppoed *_this)
#if PPPOE_NSESSION > 0xffff
#error PPPOE_NSESSION must be less than 65536
#endif
- off = arc4random() % 0xffff;
+ off = arc4random() & 0xffff;
for (i = 0; i < PPPOE_NSESSION; i++) {
- id = (i + off) % 0xffff;
+ id = (i + off) & 0xffff;
if (id == 0)
- id = (off - 1) % 0xffff;
+ id = (off - 1) & 0xffff;
if (slist_add(&_this->session_free_list, (void *)(intptr_t)id)
== NULL) {
pppoed_log(_this, LOG_ERR,