summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/ProcFS.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-08 12:49:36 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-08 12:59:06 +0100
commitfe1bf067b8045ae3410625b235e06ffcabe24b0e (patch)
tree3a206e5a91be53ef50371fd17f4549fe282b9f93 /Kernel/FileSystem/ProcFS.cpp
parent28ee5b0e98e83ea091ca249e4aed10a69d2fc26c (diff)
downloadserenity-fe1bf067b8045ae3410625b235e06ffcabe24b0e.zip
ProcFS: Reads past the end of a generated file should be zero-length
Diffstat (limited to 'Kernel/FileSystem/ProcFS.cpp')
-rw-r--r--Kernel/FileSystem/ProcFS.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index 79cf40e494..900fd69f26 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -1107,13 +1107,16 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
}
auto& data = generated_data;
- ssize_t nread = 0;
- if (data.has_value()) {
- nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
- memcpy(buffer, data.value().data() + offset, nread);
- if (nread == 0 && description && description->generator_cache())
- description->generator_cache().clear();
- }
+ if (!data.has_value())
+ return 0;
+
+ if ((size_t)offset >= data.value().size())
+ return 0;
+
+ ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
+ memcpy(buffer, data.value().data() + offset, nread);
+ if (nread == 0 && description && description->generator_cache())
+ description->generator_cache().clear();
return nread;
}