summaryrefslogtreecommitdiff
path: root/sys/compat/common
diff options
context:
space:
mode:
authorConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>2001-01-23 07:06:24 +0000
committerConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>2001-01-23 07:06:24 +0000
commit4b54aeac5a27219f7c1a9a6c94a2dfc2d6812118 (patch)
tree496b03b9b899259a61fb04ba52e32514f9a4d8df /sys/compat/common
parent5a0d2dac58166f09e64805b9e31599accb1e02d6 (diff)
Clamp malloc in compat_43_sys_getdirentries to 64k
We should really get rid of all mallocs in the compat and VOP_READDIRs.
Diffstat (limited to 'sys/compat/common')
-rw-r--r--sys/compat/common/vfs_syscalls_43.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/sys/compat/common/vfs_syscalls_43.c b/sys/compat/common/vfs_syscalls_43.c
index 5c2f52863c9..83796580c6b 100644
--- a/sys/compat/common/vfs_syscalls_43.c
+++ b/sys/compat/common/vfs_syscalls_43.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls_43.c,v 1.9 1997/11/06 22:15:52 millert Exp $ */
+/* $OpenBSD: vfs_syscalls_43.c,v 1.10 2001/01/23 07:06:23 csapuntz Exp $ */
/* $NetBSD: vfs_syscalls_43.c,v 1.4 1996/03/14 19:31:52 christos Exp $ */
/*
@@ -398,17 +398,22 @@ unionread:
} else
# endif
{
+ u_int nbytes = SCARG(uap, count);
+
+ nbytes = min(nbytes, MAXBSIZE);
+
kuio = auio;
kuio.uio_iov = &kiov;
kuio.uio_segflg = UIO_SYSSPACE;
- kiov.iov_len = SCARG(uap, count);
- MALLOC(dirbuf, caddr_t, SCARG(uap, count), M_TEMP, M_WAITOK);
+ kiov.iov_len = nbytes;
+ dirbuf = (caddr_t)malloc(nbytes, M_TEMP, M_WAITOK);
kiov.iov_base = dirbuf;
+
error = VOP_READDIR(vp, &kuio, fp->f_cred, &eofflag,
0, 0);
fp->f_offset = kuio.uio_offset;
if (error == 0) {
- readcnt = SCARG(uap, count) - kuio.uio_resid;
+ readcnt = nbytes - kuio.uio_resid;
edp = (struct dirent *)&dirbuf[readcnt];
for (dp = (struct dirent *)dirbuf; dp < edp; ) {
# if (BYTE_ORDER == LITTLE_ENDIAN)