diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-01-27 13:22:45 +0330 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-28 22:51:27 +0000 |
commit | da3c4e5df542b550d58c3031fbdb76eb681f771f (patch) | |
tree | 8ceca1cfc754e99339e537434cf32eeecaa82d58 /Userland/Libraries/LibCoredump/Reader.cpp | |
parent | 6d64b13a1baa8713a28b095ab860699c55fe4e67 (diff) | |
download | serenity-da3c4e5df542b550d58c3031fbdb76eb681f771f.zip |
LibDebug+LibCoredump: Use ByteReader to do unaligned reads
The previous solution of "lol whats a UB" was not nice and tripped over
itself when it was run under UBSAN, fix this by doing explicit
byte-by-byte reads where needed.
Diffstat (limited to 'Userland/Libraries/LibCoredump/Reader.cpp')
-rw-r--r-- | Userland/Libraries/LibCoredump/Reader.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCoredump/Reader.cpp b/Userland/Libraries/LibCoredump/Reader.cpp index 94f9f75bd6..5acb3c20d5 100644 --- a/Userland/Libraries/LibCoredump/Reader.cpp +++ b/Userland/Libraries/LibCoredump/Reader.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <AK/ByteReader.h> #include <AK/HashTable.h> #include <AK/JsonObject.h> #include <AK/JsonValue.h> @@ -139,8 +140,10 @@ Optional<FlatPtr> Reader::peek_memory(FlatPtr address) const return {}; FlatPtr offset_in_region = address - region->region_start; - const char* region_data = image().program_header(region->program_header_index).raw_data(); - return *(const FlatPtr*)(®ion_data[offset_in_region]); + auto* region_data = bit_cast<const u8*>(image().program_header(region->program_header_index).raw_data()); + FlatPtr value { 0 }; + ByteReader::load(region_data + offset_in_region, value); + return value; } const JsonObject Reader::process_info() const |