From 41dc9ace7562e46b5aef6d70ec7030dba3a2b361 Mon Sep 17 00:00:00 2001 From: andre Date: Tue, 19 Oct 2004 14:26:44 +0000 Subject: Be more careful to only index valid IP protocols and be more verbose with comments. --- sys/netinet6/ip6_input.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'sys/netinet6/ip6_input.c') diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index dc3b318..32cd04e 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -169,13 +169,22 @@ ip6_init() pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); if (pr == 0) panic("ip6_init"); + + /* Initialize the entire ip_protox[] array to IPPROTO_RAW. */ for (i = 0; i < IPPROTO_MAX; i++) ip6_protox[i] = pr - inet6sw; + /* + * Cycle through IP protocols and put them into the appropriate place + * in ip6_protox[]. + */ for (pr = (struct ip6protosw *)inet6domain.dom_protosw; pr < (struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++) if (pr->pr_domain->dom_family == PF_INET6 && - pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) - ip6_protox[pr->pr_protocol] = pr - inet6sw; + pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW) { + /* Be careful to only index valid IP protocols. */ + if (pr->pr_protocol <= IPPROTO_MAX) + ip6_protox[pr->pr_protocol] = pr - inet6sw; + } /* Initialize packet filter hooks. */ inet6_pfil_hook.ph_type = PFIL_TYPE_AF; -- cgit v1.1