summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-19 15:37:39 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-19 15:39:53 +0200
commit55dd13ccac56144cbf437584fed9b2d21be1665f (patch)
tree78c5ce4ee900103ea186062d26881c24d4f0727e
parentc0e4353bde882f86c5d7ff70f01cb91834b5b8ea (diff)
downloadserenity-55dd13ccac56144cbf437584fed9b2d21be1665f.zip
Kernel: Don't assert when reading too little from an InodeWatcher
If you provide a buffer that's too small, we'll still dequeue an event and write whatever fits in the provided buffer.
-rw-r--r--Kernel/FileSystem/InodeWatcher.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp
index 6e76cc69b6..50cb5db065 100644
--- a/Kernel/FileSystem/InodeWatcher.cpp
+++ b/Kernel/FileSystem/InodeWatcher.cpp
@@ -65,17 +65,20 @@ KResultOr<size_t> InodeWatcher::read(FileDescription&, size_t, UserOrKernelBuffe
if (!m_inode)
return 0;
- // FIXME: What should we do if the output buffer is too small?
- ASSERT(buffer_size >= (int)sizeof(Event));
auto event = m_queue.dequeue();
- ssize_t nwritten = buffer.write_buffered<sizeof(event)>(sizeof(event), [&](u8* data, size_t data_bytes) {
- memcpy(data, &event, sizeof(event));
+
+ if (buffer_size < sizeof(Event))
+ return buffer_size;
+
+ size_t bytes_to_write = min(buffer_size, sizeof(event));
+
+ ssize_t nwritten = buffer.write_buffered<sizeof(event)>(bytes_to_write, [&](u8* data, size_t data_bytes) {
+ memcpy(data, &event, bytes_to_write);
return (ssize_t)data_bytes;
});
if (nwritten < 0)
return KResult(nwritten);
- ASSERT((size_t)nwritten == sizeof(event));
- return sizeof(event);
+ return bytes_to_write;
}
KResultOr<size_t> InodeWatcher::write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t)