From 24781071d115d96b3ab1d1994a8114f4e1006fce Mon Sep 17 00:00:00 2001 From: kardel Date: Sun, 19 Mar 2006 07:02:47 +0000 Subject: [PATCH] null deref: complete linked list handling beginng condition (Coverity CID 986) --- dist/ntp/ntpd/ntp_restrict.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dist/ntp/ntpd/ntp_restrict.c b/dist/ntp/ntpd/ntp_restrict.c index 05921067535b..336387d55984 100644 --- a/dist/ntp/ntpd/ntp_restrict.c +++ b/dist/ntp/ntpd/ntp_restrict.c @@ -1,4 +1,4 @@ -/* $NetBSD: ntp_restrict.c,v 1.2 2003/12/04 16:23:37 drochner Exp $ */ +/* $NetBSD: ntp_restrict.c,v 1.3 2006/03/19 07:02:47 kardel Exp $ */ /* * ntp_restrict.c - determine host restrictions @@ -529,8 +529,13 @@ hack_restrict( rl6->addr6 = addr6; rl6->mask6 = mask6; rl6->mflags = (u_short)mflags; - rl6->next = rlprev6->next; - rlprev6->next = rl6; + if (rlprev6) { + rl6->next = rlprev6->next; + rlprev6->next = rl6; + } else { + rl6->next = restrictlist6; + restrictlist6 = rl6; + } restrictcount6++; } if ((rl6->flags ^ (u_short)flags) & @@ -566,7 +571,11 @@ hack_restrict( if (rl6 != 0 && !IN6_IS_ADDR_UNSPECIFIED(&rl6->addr6) && !(rl6->mflags & RESM_INTERFACE)) { - rlprev6->next = rl6->next; + if (rlprev6) { + rlprev6->next = rl6->next; + } else { + restrictlist6 = rl6->next; + } restrictcount6--; if (rl6->flags & RES_LIMITED) { res_limited_refcnt6--;