1 //===-- get_error_info_fuzzer.cpp -----------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
10 #include "allocator_config.h"
13 #include <fuzzer/FuzzedDataProvider.h>
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();
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();
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()))
54 scudo_error_info ErrorInfo
;
55 AllocatorT::getErrorInfo(&ErrorInfo
, FaultAddr
, StackDepot
.data(),
56 RegionInfo
.data(), RingBufferBytes
.data(), Memory
,
57 MemoryTags
, MemoryAddr
, MemorySize
);