Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dist/ipf/netinet PR/44070: Avoid zero divide in modulo o...
details: https://anonhg.NetBSD.org/src/rev/3f64fa0e9841
branches: trunk
changeset: 761977:3f64fa0e9841
user: christos <christos%NetBSD.org@localhost>
date: Sat Feb 12 18:14:21 2011 +0000
description:
PR/44070: Avoid zero divide in modulo operations.
diffstat:
sys/dist/ipf/netinet/ip_nat.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diffs (42 lines):
diff -r 5d14c66e9dc1 -r 3f64fa0e9841 sys/dist/ipf/netinet/ip_nat.c
--- a/sys/dist/ipf/netinet/ip_nat.c Sat Feb 12 18:13:46 2011 +0000
+++ b/sys/dist/ipf/netinet/ip_nat.c Sat Feb 12 18:14:21 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_nat.c,v 1.41 2010/04/17 21:00:44 darrenr Exp $ */
+/* $NetBSD: ip_nat.c,v 1.42 2011/02/12 18:14:21 christos Exp $ */
/*
* Copyright (C) 1995-2003 by Darren Reed.
@@ -120,7 +120,7 @@
#if !defined(lint)
#if defined(__NetBSD__)
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_nat.c,v 1.41 2010/04/17 21:00:44 darrenr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_nat.c,v 1.42 2011/02/12 18:14:21 christos Exp $");
#else
static const char sccsid[] = "@(#)ip_nat.c 1.11 6/5/96 (C) 1995 Darren Reed";
static const char rcsid[] = "@(#)Id: ip_nat.c,v 2.195.2.130 2010/03/16 02:24:52 darrenr Exp";
@@ -2037,7 +2037,7 @@
/*
* "ports auto" (without map-block)
*/
- if ((l > 0) && (l % np->in_ppip == 0)) {
+ if ((l > 0) && np->in_ppip && (l % np->in_ppip == 0)) {
if (l > np->in_space) {
return -1;
} else if ((l > np->in_ppip) &&
@@ -2063,8 +2063,12 @@
if (np->in_flags & IPN_SEQUENTIAL) {
port = np->in_pnext;
} else {
- port = ipf_random() % (ntohs(np->in_pmax) -
- ntohs(np->in_pmin));
+ in_port_t d = ntohs(np->in_pmax) -
+ ntohs(np->in_pmin);
+ if (d)
+ port = ipf_random() % d;
+ else
+ port = 0;
port += ntohs(np->in_pmin);
}
port = htons(port);
Home |
Main Index |
Thread Index |
Old Index