From 96cde528383c39124d45c8aee10cf3e329ee9396 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 14 Jan 2020 23:05:30 +0100 Subject: [PATCH] vfs: make fs robust against invalid ROMs An invalid ROM dataspace can occur, for example, when requesting a ROM from the report_rom service before the first report was posted. Such a node can still be useful if it's dynamic. E.g., it can be watched. Hence, the corner case of an invalid ROM dataspace should be gracefully handled instead of causing an abort. Issue #3606 --- repos/os/src/lib/vfs/rom_file_system.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/repos/os/src/lib/vfs/rom_file_system.h b/repos/os/src/lib/vfs/rom_file_system.h index 50496fd54..048aaafa4 100644 --- a/repos/os/src/lib/vfs/rom_file_system.h +++ b/repos/os/src/lib/vfs/rom_file_system.h @@ -60,7 +60,10 @@ class Vfs::Rom_file_system : public Single_file_system Genode::Allocator &alloc, Genode::Attached_rom_dataspace &rom, Rom_type type) - : Single_vfs_handle(ds, fs, alloc, 0), _rom(rom), _content_size(_init_content_size(type)) { } + : + Single_vfs_handle(ds, fs, alloc, 0), + _rom(rom), _content_size(_init_content_size(type)) + { } Read_result read(char *dst, file_size count, file_size &out_count) override @@ -74,15 +77,15 @@ class Vfs::Rom_file_system : public Single_file_system /* maximum read offset, clamped to dataspace size */ file_size const end_offset = min(count + read_offset, max_size); - /* source address within the dataspace */ - char const *src = _rom.local_addr() + read_offset; - /* check if end of file is reached */ if (read_offset >= end_offset) { out_count = 0; return READ_OK; } + /* source address within the dataspace */ + char const *src = _rom.local_addr() + read_offset; + /* copy-out bytes from ROM dataspace */ file_size const num_bytes = end_offset - read_offset;