summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorOwain Ainsworth <oga@cvs.openbsd.org>2009-06-02 11:05:10 +0000
committerOwain Ainsworth <oga@cvs.openbsd.org>2009-06-02 11:05:10 +0000
commit0797724f57c4b2cd3d9eca10af6ab148e857932a (patch)
tree28833ab64867f074d6a4617e81d7a3087f0802d7 /sys
parentf01492784049d31b694caa93d8f283626ab12430 (diff)
Fix an off-by-one in the ddb-only debugging function tdb_hashstats.
when we check if a hash chain is over 15 long, we would access one past the end of the array. change the static array size to a define because it makes this checking easier to verify. Found by Parfait. ok deraadt@.
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet/ip_ipsp.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/sys/netinet/ip_ipsp.c b/sys/netinet/ip_ipsp.c
index 625cef392b1..d156c629e99 100644
--- a/sys/netinet/ip_ipsp.c
+++ b/sys/netinet/ip_ipsp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ipsp.c,v 1.175 2009/02/16 00:31:25 dlg Exp $ */
+/* $OpenBSD: ip_ipsp.c,v 1.176 2009/06/02 11:05:09 oga Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
@@ -471,10 +471,12 @@ gettdbbysrc(union sockaddr_union *src, u_int8_t sproto,
}
#if DDB
+
+#define NBUCKETS 16
void
tdb_hashstats(void)
{
- int i, cnt, buckets[16];
+ int i, cnt, buckets[NBUCKETS];
struct tdb *tdbp;
if (tdbh == NULL) {
@@ -485,17 +487,17 @@ tdb_hashstats(void)
bzero (buckets, sizeof(buckets));
for (i = 0; i <= tdb_hashmask; i++) {
cnt = 0;
- for (tdbp = tdbh[i]; cnt < 16 && tdbp != NULL;
+ for (tdbp = tdbh[i]; cnt < NBUCKETS - 1 && tdbp != NULL;
tdbp = tdbp->tdb_hnext)
cnt++;
buckets[cnt]++;
}
db_printf("tdb cnt\t\tbucket cnt\n");
- for (i = 0; i < 16; i++)
+ for (i = 0; i < NBUCKETS; i++)
if (buckets[i] > 0)
- db_printf("%d%c\t\t%d\n", i, i == 15 ? "+" : "",
- buckets[i]);
+ db_printf("%d%c\t\t%d\n", i, i == NBUCKETS - 1 ?
+ "+" : "", buckets[i]);
}
#endif /* DDB */