fix copyout() logic. more proper fix to be done on kame tree.

This commit is contained in:
itojun 2002-08-19 23:14:39 +00:00
parent c59bd1a572
commit 041c651838
1 changed files with 19 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nd6.c,v 1.68 2002/08/19 07:23:22 itojun Exp $ */
/* $NetBSD: nd6.c,v 1.69 2002/08/19 23:14:39 itojun Exp $ */
/* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */
/*
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.68 2002/08/19 07:23:22 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.69 2002/08/19 23:14:39 itojun Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1948,11 +1948,12 @@ nd6_storelladdr(ifp, rt, m, dst, desten)
int
nd6_sysctl(name, oldp, oldlenp, newp, newlen)
int name;
void *oldp;
void *oldp; /* syscall arg, need copyout */
size_t *oldlenp;
void *newp;
void *newp; /* syscall arg, need in */
size_t newlen;
{
void *p;
size_t ol, l;
int error;
@ -1965,23 +1966,31 @@ nd6_sysctl(name, oldp, oldlenp, newp, newlen)
return EINVAL;
ol = oldlenp ? *oldlenp : 0;
if (oldp) {
p = malloc(*oldlenp, M_TEMP, M_WAITOK);
if (!p)
return ENOMEM;
} else
p = NULL;
switch (name) {
case ICMPV6CTL_ND6_DRLIST:
error = fill_drlist(oldp, oldlenp, ol);
if (!error && oldp)
copyout(oldp, oldp, *oldlenp);
error = fill_drlist(p, oldlenp, ol);
if (!error && p && oldp)
copyout(p, oldp, *oldlenp);
break;
case ICMPV6CTL_ND6_PRLIST:
error = fill_prlist(oldp, oldlenp, ol);
if (!error && oldp)
copyout(oldp, oldp, *oldlenp);
error = fill_prlist(p, oldlenp, ol);
if (!error && p && oldp)
copyout(p, oldp, *oldlenp);
break;
default:
error = ENOPROTOOPT;
break;
}
if (p)
free(p, M_TEMP);
return(error);
}