From c9b6e084a323b9472a5506dd63b9841126600c4f Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Tue, 1 Sep 2020 12:36:26 -0700 Subject: [PATCH] Do not create a map with start == end. This is not possible in the real world, so prevent this particular case to avoid leaking memory and any other issues. Bug: 165619316 Test: Verified the fuzzer test case that caused a leak no longer leaks. Change-Id: I352b3bd21a4931432e015af89c256ddbcdaa1070 --- libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp b/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp index 0415ef684..9c5374a5b 100644 --- a/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp +++ b/libunwindstack/tests/fuzz/UnwinderComponentCreator.cpp @@ -127,6 +127,13 @@ std::unique_ptr GetMaps(FuzzedDataProvider* data_provider) { for (uint8_t i = 0; i < entry_count; i++) { uint64_t start = AlignToPage(data_provider->ConsumeIntegral()); uint64_t end = AlignToPage(data_provider->ConsumeIntegralInRange(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);