Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / scudo / standalone / fuzz / get_error_info_fuzzer.cpp
blob74456450a476126536c96e20090533c898e05190
1 //===-- get_error_info_fuzzer.cpp -----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #define SCUDO_FUZZ
10 #include "allocator_config.h"
11 #include "combined.h"
13 #include <fuzzer/FuzzedDataProvider.h>
15 #include <string>
16 #include <vector>
18 extern "C" int LLVMFuzzerTestOneInput(uint8_t *Data, size_t Size) {
19 using AllocatorT = scudo::Allocator<scudo::AndroidConfig>;
20 FuzzedDataProvider FDP(Data, Size);
22 uintptr_t FaultAddr = FDP.ConsumeIntegral<uintptr_t>();
23 uintptr_t MemoryAddr = FDP.ConsumeIntegral<uintptr_t>();
25 std::string MemoryAndTags =
26 FDP.ConsumeRandomLengthString(FDP.remaining_bytes());
27 const char *Memory = MemoryAndTags.c_str();
28 // Assume 16-byte alignment.
29 size_t MemorySize = (MemoryAndTags.length() / 17) * 16;
30 const char *MemoryTags = Memory + MemorySize;
32 std::string StackDepotBytes =
33 FDP.ConsumeRandomLengthString(FDP.remaining_bytes());
34 std::vector<char> StackDepot(sizeof(scudo::StackDepot), 0);
35 for (size_t i = 0; i < StackDepotBytes.length() && i < StackDepot.size();
36 ++i) {
37 StackDepot[i] = StackDepotBytes[i];
40 std::string RegionInfoBytes =
41 FDP.ConsumeRandomLengthString(FDP.remaining_bytes());
42 std::vector<char> RegionInfo(AllocatorT::getRegionInfoArraySize(), 0);
43 for (size_t i = 0; i < RegionInfoBytes.length() && i < RegionInfo.size();
44 ++i) {
45 RegionInfo[i] = RegionInfoBytes[i];
48 std::string RingBufferBytes = FDP.ConsumeRemainingBytesAsString();
49 // RingBuffer is too short.
50 if (!AllocatorT::setRingBufferSizeForBuffer(RingBufferBytes.data(),
51 RingBufferBytes.size()))
52 return 0;
54 scudo_error_info ErrorInfo;
55 AllocatorT::getErrorInfo(&ErrorInfo, FaultAddr, StackDepot.data(),
56 RegionInfo.data(), RingBufferBytes.data(), Memory,
57 MemoryTags, MemoryAddr, MemorySize);
58 return 0;