diff options
author | trasz <trasz@FreeBSD.org> | 2015-11-20 14:08:12 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2015-11-20 14:08:12 +0000 |
commit | a6632d64f50cbf7cb63cee17f6b163f2965de037 (patch) | |
tree | 6983d3ba1bd4837be3f9711537ca3c0df9a2e67d /sys | |
parent | bbdebe789d20de1b318c709211ce23aa4d276056 (diff) | |
download | FreeBSD-src-a6632d64f50cbf7cb63cee17f6b163f2965de037.zip FreeBSD-src-a6632d64f50cbf7cb63cee17f6b163f2965de037.tar.gz |
The freebsd4_getfsstat() was broken in r281551 to always return 0 on success.
All versions of getfsstat(3) are supposed to return the number of [o]statfs
structs in the array that was copied out.
Also fix missing bounds checking and signed comparison of unsigned types.
Submitted by: bde@
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/vfs_syscalls.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index ce4436a..c246b9e 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -435,6 +435,8 @@ sys_getfsstat(td, uap) size_t count; int error; + if (uap->bufsize < 0 || uap->bufsize > SIZE_MAX) + return (EINVAL); error = kern_getfsstat(td, &uap->buf, uap->bufsize, &count, UIO_USERSPACE, uap->flags); if (error == 0) @@ -625,13 +627,18 @@ freebsd4_getfsstat(td, uap) size_t count, size; int error; + if (uap->bufsize < 0) + return (EINVAL); count = uap->bufsize / sizeof(struct ostatfs); + if (count > SIZE_MAX / sizeof(struct statfs)) + return (EINVAL); size = count * sizeof(struct statfs); error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->flags); - if (size > 0) { + td->td_retval[0] = count; + if (size != 0) { sp = buf; - while (count > 0 && error == 0) { + while (count != 0 && error == 0) { cvtstatfs(sp, &osb); error = copyout(&osb, uap->buf, sizeof(osb)); sp++; @@ -640,8 +647,6 @@ freebsd4_getfsstat(td, uap) } free(buf, M_TEMP); } - if (error == 0) - td->td_retval[0] = count; return (error); } |