Refine bounds check code.

This commit is contained in:
david 2004-11-07 04:08:37 +00:00
parent 4614af85f7
commit bf4bf03db8
3 changed files with 29 additions and 20 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: darwin_route.c,v 1.7 2004/10/27 19:29:57 david Exp $ */
/* $NetBSD: darwin_route.c,v 1.8 2004/11/07 04:08:37 david Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: darwin_route.c,v 1.7 2004/10/27 19:29:57 david Exp $");
__KERNEL_RCSID(0, "$NetBSD: darwin_route.c,v 1.8 2004/11/07 04:08:37 david Exp $");
#include <sys/errno.h>
#include <sys/systm.h>
@ -89,9 +89,10 @@ darwin_ifaddrs(af, dst, sizep)
#endif
continue;
}
if (native_to_darwin_sockaddr((struct sockaddr *)laddr,
&dladdr) == EINVAL)
return EINVAL;
error = native_to_darwin_sockaddr((struct sockaddr *)laddr,
&dladdr);
if (error)
return error;
dim.dim_len = sizeof(dim) + ALIGN(dladdr.ss_len);
dim.dim_vers = DARWIN_RTM_VERSION;
@ -270,8 +271,9 @@ copyout_sockaddr(sap, dstp, sizep, maxsize)
size_t len;
int error;
if (native_to_darwin_sockaddr(sap, &ss) == EINVAL)
return EINVAL;
error = native_to_darwin_sockaddr(sap, &ss);
if (error)
return error;
len = ss.ss_len;
*sizep += ALIGN(len);

View File

@ -1,4 +1,4 @@
/* $NetBSD: darwin_socket.c,v 1.6 2004/10/27 19:29:57 david Exp $ */
/* $NetBSD: darwin_socket.c,v 1.7 2004/11/07 04:08:37 david Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: darwin_socket.c,v 1.6 2004/10/27 19:29:57 david Exp $");
__KERNEL_RCSID(0, "$NetBSD: darwin_socket.c,v 1.7 2004/11/07 04:08:37 david Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -149,7 +149,7 @@ native_to_darwin_sockaddr(nsa, dsa)
if ((len = nsa->sa_len) > _SS_MAXSIZE) {
printf("native_to_darwin_sockaddr: sa_len too big");
return 0;
return EINVAL;
}
memcpy(dsa, nsa, len);
@ -270,7 +270,8 @@ darwin_sys_recvfrom(l, v, retval)
if ((error = copyin(nssp, &nss, sizeof(nss))) != 0)
return error;
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss, &dss)) != 0)
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss,
&dss)) != 0)
return error;
if ((error = copyin(SCARG(uap, fromlenaddr), &len, sizeof(len))) != 0)
@ -322,7 +323,8 @@ darwin_sys_accept(l, v, retval)
if ((error = copyin(nssp, &nss, sizeof(nss))) != 0)
return error;
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss, &dss)) != 0)
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss,
&dss)) != 0)
return error;
if ((error = copyin(SCARG(uap, anamelen), &len, sizeof(len))) != 0)
@ -374,7 +376,8 @@ darwin_sys_getpeername(l, v, retval)
if ((error = copyin(nssp, &nss, sizeof(nss))) != 0)
return error;
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss, &dss)) != 0)
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss,
&dss)) != 0)
return error;
if ((error = copyin(SCARG(uap, alen), &len, sizeof(len))) != 0)
@ -426,7 +429,8 @@ darwin_sys_getsockname(l, v, retval)
if ((error = copyin(nssp, &nss, sizeof(nss))) != 0)
return error;
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss, &dss)) != 0)
if ((error = native_to_darwin_sockaddr((struct sockaddr *)&nss,
&dss)) != 0)
return error;
if ((error = copyin(SCARG(uap, alen), &len, sizeof(len))) != 0)
@ -471,7 +475,8 @@ darwin_sys_connect(l, v, retval)
if ((error = copyin(SCARG(uap, name), &dss, sizeof(dss))) != 0)
return error;
if ((error = darwin_to_native_sockaddr((struct sockaddr *)&dss, &nss)) != 0)
if ((error = darwin_to_native_sockaddr((struct sockaddr *)&dss,
&nss)) != 0)
return error;
len = SCARG(uap, namelen);
@ -513,7 +518,8 @@ darwin_sys_bind(l, v, retval)
if ((error = copyin(SCARG(uap, name), &dss, sizeof(dss))) != 0)
return error;
if ((error = darwin_to_native_sockaddr((struct sockaddr *)&dss, &nss)) != 0)
if ((error = darwin_to_native_sockaddr((struct sockaddr *)&dss,
&nss)) != 0)
return error;
len = SCARG(uap, namelen);
@ -558,7 +564,8 @@ darwin_sys_sendto(l, v, retval)
if ((error = copyin(SCARG(uap, to), &dss, sizeof(dss))) != 0)
return error;
if ((error = darwin_to_native_sockaddr((struct sockaddr *)&dss, &nss)) != 0)
if ((error = darwin_to_native_sockaddr((struct sockaddr *)&dss,
&nss)) != 0)
return error;
len = SCARG(uap, tolen);

View File

@ -1,4 +1,4 @@
/* $NetBSD: hpux_tty.c,v 1.27 2004/10/27 19:29:57 david Exp $ */
/* $NetBSD: hpux_tty.c,v 1.28 2004/11/07 04:08:37 david Exp $ */
/*
* Copyright (c) 1990, 1993
@ -82,7 +82,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: hpux_tty.c,v 1.27 2004/10/27 19:29:57 david Exp $");
__KERNEL_RCSID(0, "$NetBSD: hpux_tty.c,v 1.28 2004/11/07 04:08:37 david Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_43.h"
@ -514,7 +514,7 @@ hpuxtobsdbaud(hpux_speed)
B0, B0, B0, B0, B0, B0, EXTA, EXTB
};
if (hpux_speed < 0)
if (hpux_speed < 0 || hpux_speed > 31)
return(B0);
return(hpuxtobsdbaudtab[hpux_speed & TIO_CBAUD]);
}