diff options
author | Justin DeMartino <jjdemartino@google.com> | 2020-10-14 19:39:53 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-10-14 19:39:53 +0000 |
commit | 0d11af03e43f110b0bb160f7e20436d0043e3038 (patch) | |
tree | 48f8bcca856276ec73a86dd3fb26143d3ca64578 /libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp | |
parent | 075666ebd0dee8d0c4a2efa54f7c324a3f67ee2a (diff) | |
parent | a6c01e4e98d2b343dcecfc99611e2e6250c730db (diff) |
Merge changes from topic "SP1A.200921.001" into s-keystone-qcom-dev
* changes:
fs_mgr: adb-remount-test.sh: filter out more administrivia mounts.
Merge SP1A.200921.001 Change-Id: I90b97c4e9fb10b1f45e74def404823eed5b1aaa8
Diffstat (limited to 'libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp')
-rw-r--r-- | libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp b/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp index 94f5a73cd..9c5374a5b 100644 --- a/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp +++ b/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp @@ -16,6 +16,11 @@ #include "UnwinderComponentCreator.h" +#include <map> +#include <memory> +#include <string> +#include <vector> + std::unique_ptr<Regs> GetRegisters(ArchEnum arch) { switch (arch) { case unwindstack::ARCH_ARM: { @@ -109,13 +114,35 @@ ElfFake* PopulateElfFake(FuzzedDataProvider* data_provider) { return elf; } +static constexpr size_t kPageSize = 4096; + +static constexpr uint64_t AlignToPage(uint64_t address) { + return (address + kPageSize - 1) & ~(kPageSize - 1); +} + std::unique_ptr<Maps> GetMaps(FuzzedDataProvider* data_provider) { std::unique_ptr<Maps> maps = std::make_unique<Maps>(); + std::map<uint64_t, uint64_t> map_ends; uint8_t entry_count = data_provider->ConsumeIntegralInRange<uint8_t>(0, kMaxMapEntryCount); for (uint8_t i = 0; i < entry_count; i++) { - uint64_t start = data_provider->ConsumeIntegral<uint64_t>(); - uint64_t end = data_provider->ConsumeIntegralInRange<uint64_t>(start, UINT64_MAX); - uint64_t offset = data_provider->ConsumeIntegral<uint64_t>(); + uint64_t start = AlignToPage(data_provider->ConsumeIntegral<uint64_t>()); + uint64_t end = AlignToPage(data_provider->ConsumeIntegralInRange<uint64_t>(start, UINT64_MAX)); + if (start == end) { + // It's impossible to see start == end in the real world, so + // make sure the map contains at least one page of data. + if (__builtin_add_overflow(end, 0x1000, &end)) { + continue; + } + } + // Make sure not to add overlapping maps, that is not something that can + // happen in the real world. + auto entry = map_ends.upper_bound(start); + if (entry != map_ends.end() && end > entry->second) { + continue; + } + map_ends[end] = start; + + uint64_t offset = AlignToPage(data_provider->ConsumeIntegral<uint64_t>()); std::string map_info_name = data_provider->ConsumeRandomLengthString(kMaxMapInfoNameLen); uint8_t flags = PROT_READ | PROT_WRITE; |