1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:37:34 +00:00

ProcFS: Check for empty Optional in read_bytes()

In read_bytes() we now check that the Optional "data" actually
contains a value before use, avoiding a failing asserting in
kernel space.
This commit is contained in:
Drew Stratford 2019-10-22 22:45:48 +13:00 committed by Andreas Kling
parent 4d99856f95
commit d063734f69

View file

@ -997,10 +997,14 @@ ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
} }
auto& data = generated_data; auto& data = generated_data;
ssize_t nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count)); ssize_t nread = 0;
memcpy(buffer, data.value().data() + offset, nread); if (data.has_value()) {
if (nread == 0 && description && description->generator_cache()) nread = min(static_cast<off_t>(data.value().size() - offset), static_cast<off_t>(count));
description->generator_cache().clear(); memcpy(buffer, data.value().data() + offset, nread);
if (nread == 0 && description && description->generator_cache())
description->generator_cache().clear();
}
return nread; return nread;
} }