kernel: add assert in _user_read_dir

* This will help catch bugs such as in #15607.

Change-Id: I25b28932f9db4e2abe8499dd829c910bb565086b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2082
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
X512 2020-01-08 01:53:33 +09:00 committed by waddlesplash
parent 3e818f2075
commit 2cf8f0ee6b
1 changed files with 4 additions and 0 deletions

View File

@ -984,6 +984,8 @@ _user_read_dir(int fd, struct dirent* userBuffer, size_t bufferSize,
if (status != B_OK)
return status;
ASSERT(count <= maxCount);
// copy the buffer back -- determine the total buffer size first
size_t sizeToCopy = 0;
BytePointer<struct dirent> entry = buffer;
@ -993,6 +995,8 @@ _user_read_dir(int fd, struct dirent* userBuffer, size_t bufferSize,
entry += length;
}
ASSERT(sizeToCopy <= bufferSize);
if (user_memcpy(userBuffer, buffer, sizeToCopy) != B_OK)
return B_BAD_ADDRESS;